private void defaultVisit(CFrame frame) {
    MultiGraph graph = this.view.getGraph();
    graph.getNodeSet().clear();
    graph.getEdgeSet().clear();

    // this.baseIRIList = new HashSet<String>();

    // Получение всех элементов и формирование из них визуального части.
    for (OWLNamedIndividual owlName : frame.getContent().getConcepts()) {
      String label = this.model.getLabel(owlName);

      if (label.equals("_EMPTY_")) {
        label = owlName.getIRI().getFragment().toString();
      }

      Node node = graph.addNode(owlName.getIRI().toString());
      node.addAttribute("OWLNamedIndividual", owlName);
      node.addAttribute("ui.label", label);

      if (owlName.getIRI().equals(frame.getTrgConcept().getIRI())) {
        node.setAttribute("ui.class", "concept");
      }
    }

    // Связывает все элементы линиями.
    for (Branch br : frame.getContent().getBranches()) {
      Node nodeSub = null;
      Node nodeObj = null;

      for (Node node : graph.getNodeSet()) {

        if (node.getId().equals(br.getSubject().getIRI().toString())) {
          nodeSub = node;
          continue;
        } else {
          if (node.getId().equals(br.getObject().getIRI().toString())) {
            nodeObj = node;
            continue;
          }
        }

        if (nodeSub != null && nodeObj != null) {
          break;
        }
      }

      // Создает элемент линия для двух node.
      Edge edge = graph.addEdge(br.getBrachIndIRI().toString(), nodeSub, nodeObj, true);

      String labelEdge = this.model.getAnnotationValue(br.getPrp().getIRI());

      if (labelEdge.equals("_EMPTY_")) {
        labelEdge = br.getPrp().getIRI().getFragment().toString();
      }

      edge.addAttribute("ui.label", labelEdge);
    }
  }
  // For adding Node To Graph
  public void AddNodeToGraph(String IP, boolean IsSwitch) {
    String temp;

    if (IsSwitch) {
      temp = "OpenVSwitch";
    } else {
      temp = "EndHost";
    }

    network_graph.addNode(temp + " [" + IP + "]");
    Node node = network_graph.getNode(temp + " [" + IP + "]");
    node.addAttribute("ui.class", temp);
    node.addAttribute("ui.label", node.getId());
  }
  public static void main(String[] args) throws PyException, IOException {

    String[] argss = new String[] {"C:\\Python27\\python.exe", "D:\\pydemo.py", "D:\\large.txt"};

    readInputFile(argss[2], 1);
    createGraph(network);
    Process process = null;
    try {
      process = Runtime.getRuntime().exec(argss);
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    InputStream inputStream = process.getInputStream();
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

    String line;
    int i = -1;
    try {
      while ((line = bufferedReader.readLine()) != null) {
        System.out.println(line);

        if (line.equals("Community: ")) {
          i++;
        } else {
          Node node = graph.getNode(line);
          if (node != null) {
            node.addAttribute("ui.label", i + "");
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println("Num of Nodes:" + network.nNodes);
    System.out.println("Num of Edges:" + network.nEdges);
    System.out.println("Num of Communities:" + (i + 1));
  }
  @Override
  public MyGraph generate(int nbVertex, int nbChips) {
    MyGraph graph = new MyGraph(false);

    if (nbVertex <= 1) {
      return graph;
    }

    int i = 1, j = 1;

    while (j < nbVertex) {
      j++;
      graph.addEdge("" + i + "" + j, "" + i, "" + j, true);
      i++;
    }

    graph.addEdge("" + nbVertex + "1", "" + nbVertex, "1", true);

    for (Node node : graph.getNodeSet()) {
      node.addAttribute("label", nbChips);
    }

    return graph;
  }
Exemplo n.º 5
0
  /*
   * (non-Javadoc)
   *
   * @see org.graphstream.algorithm.Algorithm#compute()
   */
  @SuppressWarnings("unchecked")
  public void compute() {
    Node source = graph.getNode(this.source_id);

    // Step 1: Initialize graph

    for (Node n : graph) {
      if (n == source) n.addAttribute(identifier + ".distance", 0.0);
      else n.addAttribute(identifier + ".distance", Double.POSITIVE_INFINITY);

      // n.addAttribute(identifier+".predecessors",(Object)null);
    }

    // Step 2: relax edges repeatedly

    for (int i = 0; i < graph.getNodeCount(); i++) {
      for (Edge e : graph.getEachEdge()) {
        Node n0 = e.getNode0();
        Node n1 = e.getNode1();
        Double d0 = (Double) n0.getAttribute(identifier + ".distance");
        Double d1 = (Double) n1.getAttribute(identifier + ".distance");

        Double we = (Double) e.getAttribute(weightAttribute);
        if (we == null)
          throw new NumberFormatException(
              "org.graphstream.algorithm.BellmanFord: Problem with attribute \""
                  + weightAttribute
                  + "\" on edge "
                  + e);

        if (d0 != null) {
          if (d1 == null || d1 >= d0 + we) {
            n1.addAttribute(identifier + ".distance", d0 + we);
            ArrayList<Edge> predecessors =
                (ArrayList<Edge>) n1.getAttribute(identifier + ".predecessors");

            if (d1 != null && d1 == d0 + we) {
              if (predecessors == null) {
                predecessors = new ArrayList<Edge>();
              }
            } else {
              predecessors = new ArrayList<Edge>();
            }
            if (!predecessors.contains(e)) {
              predecessors.add(e);
            }

            n1.addAttribute(identifier + ".predecessors", predecessors);
          }
        }
      }
    }

    // Step 3: check for negative-weight cycles

    for (Edge e : graph.getEachEdge()) {
      Node n0 = e.getNode0();
      Node n1 = e.getNode1();
      Double d0 = (Double) n0.getAttribute(identifier + ".distance");
      Double d1 = (Double) n1.getAttribute(identifier + ".distance");

      Double we = (Double) e.getAttribute(weightAttribute);

      if (we == null) {
        throw new NumberFormatException(
            String.format(
                "%s: Problem with attribute \"%s\" on edge \"%s\"",
                BellmanFord.class.getName(), weightAttribute, e.getId()));
      }

      if (d1 > d0 + we) {
        throw new NumberFormatException(
            String.format(
                "%s: Problem: negative weight, cycle detected on edge \"%s\"",
                BellmanFord.class.getName(), e.getId()));
      }
    }
  }