Exemplo n.º 1
0
 public static SubGraph getABackup(GraphModel g) {
   SubGraph ret = new SubGraph(g);
   for (VertexModel v : g) {
     ret.vertices.add(v);
   }
   for (EdgeModel e : g.edges()) {
     ret.edges.add(e);
   }
   return ret;
 }
Exemplo n.º 2
0
 public static GraphModel getACopy(GraphModel g) {
   GraphModel ret = new GraphModel(g.isDirected());
   VertexModel[] map = new VertexModel[g.getVerticesCount()];
   for (VertexModel v : g) {
     VertexModel t = new VertexModel(v);
     map[v.getId()] = t;
     ret.insertVertex(t);
   }
   for (EdgeModel e : g.edges()) {
     EdgeModel t = new EdgeModel(e, map[e.source.getId()], map[e.target.getId()]);
     ret.insertEdge(t);
     setDup(e, t);
   }
   return ret;
 }
Exemplo n.º 3
0
 static GraphModel createUndirectedCopy(GraphModel network) {
   GraphModel U = new GraphModel(false);
   for (VertexModel scan : network) {
     VertexModel dup = new VertexModel(scan);
     U.addVertex(dup);
     scan.getProp().obj = dup;
     dup.getProp().obj = scan;
   }
   for (EdgeModel scan : network.edges()) {
     EdgeModel dup =
         new EdgeModel(
             scan,
             (VertexModel) scan.source.getProp().obj,
             (VertexModel) scan.target.getProp().obj);
     U.addEdge(dup);
     setDup(scan, dup);
   }
   return U;
 }
Exemplo n.º 4
0
  @Override
  public void doAlgorithm() {

    step("TEST the step");
    GraphModel g = graphData.getGraph();
    Vertex v1 = requestVertex(g, "select the first vertex");
    Vertex v2 = requestVertex(g, "select the second vertex");
    step("color v1 and v2");
    v1.setColor(2);
    v2.setColor(2);

    step("mark v1 neighbours");
    for (Vertex v : g.neighbors(v1)) v.setMark(true);

    step("color v1 edges");
    for (Edge e : g.edges(v1)) e.setColor(3);

    step("connect v2 to the neighbors of its neighbours");
    Vector<Edge> toInsert = new Vector<Edge>();
    for (Vertex v : g.neighbors(v2))
      for (Vertex vv : g.neighbors(v)) toInsert.add(new Edge(v2, vv));
    g.insertEdges(toInsert);

    step("mark the path connecting v1 and v2, using helper methods in AlgorithmUtils");
    Path<Vertex> path = AlgorithmUtils.getPath(g, v1, v2);
    Vertex last = v2;
    for (Vertex v : path) {
      Edge e = g.getEdge(v, last);
      if (e != null) e.setColor(6);
      last = v;
    }

    step("the graph matrix<br>" + getMatrixHTML(g));

    step("That's it!");
    step("Start making your algorithm by modifing this file, and running make.sh");
    step("have fun :)");
  }