// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/GraphComputer.java
// public interface GraphComputer {
// 
//     public enum Isolation {
//         /**
//          * Computations are carried out in a bulk synchronous manner.
//          * The results of a vertex property update are only visible after the round is complete.
//          */
//         BSP,
//         /**
//          * Computations are carried out in a bulk synchronous manner.
//          * The results of a vertex property update are visible before the end of the round.
//          */
//         DIRTY_BSP
//     }
// 
//     /**
//      * Execute the GraphComputer's VertexProgram against the GraphComputer's graph.
//      * The GraphComputer must have reference to a VertexProgram and Graph.
//      * The typical flow of execution is:
//      *  1. Set up the VertexMemory as necessary given the VertexProgram (e.g. set compute keys).
//      *  2. Set up the GraphMemory as necessary given the VertexProgram.
//      *  3. Execute the VertexProgram
//      */
//     public void execute();
// 
//     /**
//      * Get the VertexSystemMemory cast as a VertexMemory to hide system specific methods.
//      *
//      * @return the GraphComputer's VertexMemory
//      */
//     public VertexMemory getVertexMemory();
// 
//     /**
//      * Get the GraphSystemMemory cast as a GraphMemory to hide system specific methods.
//      *
//      * @return the GraphComputer's GraphMemory
//      */
//     public GraphMemory getGraphMemory();
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/VertexMemory.java
// public interface VertexMemory {
// 
//     public void setProperty(Vertex vertex, String key, Object value);
// 
//     public <T> T getProperty(Vertex vertex, String key);
// 
//     public <T> T removeProperty(Vertex vertex, String key);
// 
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/computers/SerialGraphComputer.java
// public class SerialGraphComputer extends AbstractGraphComputer {
// 
//     public SerialGraphComputer(final Graph graph, final VertexProgram vertexProgram, final Isolation isolation) {
//         super(graph, vertexProgram, new SimpleGraphMemory(), new SimpleVertexMemory(isolation), isolation);
//     }
// 
//     public void execute() {
//         final long time = System.currentTimeMillis();
//         this.vertexMemory.setComputeKeys(this.vertexProgram.getComputeKeys());
//         this.vertexProgram.setup(this.graphMemory);
// 
//         final CoreShellVertex coreShellVertex = new CoreShellVertex(this.vertexMemory);
// 
//         Preconditions.checkArgument(this.graph.getFeatures().supportsVertexIteration);
// 
//         boolean done = false;
//         while (!done) {
//             for (final Vertex vertex : this.graph.getVertices()) {
//                 coreShellVertex.setBaseVertex(vertex);
//                 this.vertexProgram.execute(coreShellVertex, this.graphMemory);
//             }
//             this.vertexMemory.completeIteration();
//             this.graphMemory.incrIteration();
//             done = this.vertexProgram.terminate(this.graphMemory);
//         }
// 
//         this.graphMemory.setRuntime(System.currentTimeMillis() - time);
//     }
// }


import com.google.common.collect.ImmutableSortedMap;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory;
import com.tinkerpop.furnace.algorithms.vertexcentric.GraphComputer;
import com.tinkerpop.furnace.algorithms.vertexcentric.VertexMemory;
import com.tinkerpop.furnace.algorithms.vertexcentric.computers.SerialGraphComputer;
import junit.framework.TestCase;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
            map.put(vertex.getProperty("name") + " ", pageRank);
        }
        for (Map.Entry<String, Double> entry : ImmutableSortedMap.copyOf(map, new Comparator<String>() {
            public int compare(final String key, final String key2) {
                int c = map.get(key2).compareTo(map.get(key));
                return c == 0 ? -1 : c;
            }
        }).entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }

        System.out.println(total);
        System.out.println(computer.getGraphMemory().getRuntime());

        /*for (int i = 1; i < 7; i++) {
            double PAGE_RANK = result.getResult(graph.getVertex(i));
            System.out.println(i + " " + (PAGE_RANK / total));
        }*/


    }

    public void testWeightedPageRankDegenerateToPageRank() throws Exception {
        Graph graph = TinkerGraphFactory.createTinkerGraph();

        WeightedPageRankProgram program1 = WeightedPageRankProgram.create().vertexCount(6).build();
        SerialGraphComputer computer1 = new SerialGraphComputer(graph, program1, GraphComputer.Isolation.BSP);
        computer1.execute();

        PageRankProgram program2 = PageRankProgram.create().vertexCount(6).build();
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/GraphComputer.java
// public interface GraphComputer {
// 
//     public enum Isolation {
//         /**
//          * Computations are carried out in a bulk synchronous manner.
//          * The results of a vertex property update are only visible after the round is complete.
//          */
//         BSP,
//         /**
//          * Computations are carried out in a bulk synchronous manner.
//          * The results of a vertex property update are visible before the end of the round.
//          */
//         DIRTY_BSP
//     }
// 
//     /**
//      * Execute the GraphComputer's VertexProgram against the GraphComputer's graph.
//      * The GraphComputer must have reference to a VertexProgram and Graph.
//      * The typical flow of execution is:
//      *  1. Set up the VertexMemory as necessary given the VertexProgram (e.g. set compute keys).
//      *  2. Set up the GraphMemory as necessary given the VertexProgram.
//      *  3. Execute the VertexProgram
//      */
//     public void execute();
// 
//     /**
//      * Get the VertexSystemMemory cast as a VertexMemory to hide system specific methods.
//      *
//      * @return the GraphComputer's VertexMemory
//      */
//     public VertexMemory getVertexMemory();
// 
//     /**
//      * Get the GraphSystemMemory cast as a GraphMemory to hide system specific methods.
//      *
//      * @return the GraphComputer's GraphMemory
//      */
//     public GraphMemory getGraphMemory();
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/VertexMemory.java
// public interface VertexMemory {
// 
//     public void setProperty(Vertex vertex, String key, Object value);
// 
//     public <T> T getProperty(Vertex vertex, String key);
// 
//     public <T> T removeProperty(Vertex vertex, String key);
// 
// }
// 
// Path: src/main/java/com/tinkerpop/furnace/algorithms/vertexcentric/computers/SerialGraphComputer.java
// public class SerialGraphComputer extends AbstractGraphComputer {
// 
//     public SerialGraphComputer(final Graph graph, final VertexProgram vertexProgram, final Isolation isolation) {
//         super(graph, vertexProgram, new SimpleGraphMemory(), new SimpleVertexMemory(isolation), isolation);
//     }
// 
//     public void execute() {
//         final long time = System.currentTimeMillis();
//         this.vertexMemory.setComputeKeys(this.vertexProgram.getComputeKeys());
//         this.vertexProgram.setup(this.graphMemory);
// 
//         final CoreShellVertex coreShellVertex = new CoreShellVertex(this.vertexMemory);
// 
//         Preconditions.checkArgument(this.graph.getFeatures().supportsVertexIteration);
// 
//         boolean done = false;
//         while (!done) {
//             for (final Vertex vertex : this.graph.getVertices()) {
//                 coreShellVertex.setBaseVertex(vertex);
//                 this.vertexProgram.execute(coreShellVertex, this.graphMemory);
//             }
//             this.vertexMemory.completeIteration();
//             this.graphMemory.incrIteration();
//             done = this.vertexProgram.terminate(this.graphMemory);
//         }
// 
//         this.graphMemory.setRuntime(System.currentTimeMillis() - time);
//     }
// }


// Path: src/test/java/com/tinkerpop/furnace/algorithms/vertexcentric/programs/ranking/WeightedPageRankProgramTest.java
import com.google.common.collect.ImmutableSortedMap;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.tg.TinkerGraphFactory;
import com.tinkerpop.furnace.algorithms.vertexcentric.GraphComputer;
import com.tinkerpop.furnace.algorithms.vertexcentric.VertexMemory;
import com.tinkerpop.furnace.algorithms.vertexcentric.computers.SerialGraphComputer;
import junit.framework.TestCase;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

            map.put(vertex.getProperty("name") + " ", pageRank);
        }
        for (Map.Entry<String, Double> entry : ImmutableSortedMap.copyOf(map, new Comparator<String>() {
            public int compare(final String key, final String key2) {
                int c = map.get(key2).compareTo(map.get(key));
                return c == 0 ? -1 : c;
            }
        }).entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }

        System.out.println(total);
        System.out.println(computer.getGraphMemory().getRuntime());

        /*for (int i = 1; i < 7; i++) {
            double PAGE_RANK = result.getResult(graph.getVertex(i));
            System.out.println(i + " " + (PAGE_RANK / total));
        }*/


    }

    public void testWeightedPageRankDegenerateToPageRank() throws Exception {
        Graph graph = TinkerGraphFactory.createTinkerGraph();

        WeightedPageRankProgram program1 = WeightedPageRankProgram.create().vertexCount(6).build();
        SerialGraphComputer computer1 = new SerialGraphComputer(graph, program1, GraphComputer.Isolation.BSP);
        computer1.execute();

        PageRankProgram program2 = PageRankProgram.create().vertexCount(6).build();
        SerialGraphComputer computer2 = new SerialGraphComputer(graph, program2, GraphComputer.Isolation.BSP);