Esempio n. 1
0
        public object Clone()
        {
            var newGraph = new TravelGraph();

            newGraph.AddVertexRange(this.Vertices);
            newGraph.AddEdgeRange(this.Edges);
            newGraph._Costs = new Dictionary <TravelEdge, double>(_Costs, _Costs.Comparer);
            return(newGraph);
        }
Esempio n. 2
0
        public IEnumerable <TravelPath> findCheapestFirePaths(int startLocation)
        {
            //reduction: want to find chepest path that include  edge with fire
            // insert node "inside" the fire edges and calculate the distance to it
            //in order to get the right the path insert "opposite" edge inside the fire edge
            //with cost infinity.
            //edges between real node and virtual node will be with original cost
            TravelGraph           reductionGraph     = createWorldWithClearWays();
            List <int>            fireNodes          = new List <int>();
            int                   generatePlace      = reductionGraph.Vertices.Max();
            Dictionary <int, int> virtualToRealPlace = new Dictionary <int, int>();

            foreach (var edge in _fireWays)
            {
                var newNodeTarget = ++generatePlace;
                reductionGraph.AddVertex(newNodeTarget);

                var newNodeSource = ++generatePlace;
                reductionGraph.AddVertex(newNodeSource);

                reductionGraph.AddEdge(new TravelEdge(edge.Source, newNodeTarget), _graph.GetCost(edge));
                reductionGraph.AddEdge(new TravelEdge(newNodeSource, edge.Target), _graph.GetCost(edge));

                //opposite edge
                virtualToRealPlace.Add(newNodeTarget, edge.Target);
                virtualToRealPlace.Add(newNodeSource, edge.Source);
                reductionGraph.AddEdge(new TravelEdge(newNodeSource, newNodeTarget), double.MaxValue);

                fireNodes.Add(newNodeSource);
                fireNodes.Add(newNodeTarget);
            }

            var paths = reductionGraph.findChepestPaths(startLocation, fireNodes.ToArray()).ToArray();

            foreach (var path in paths)
            {
                foreach (var virt in virtualToRealPlace.Keys)
                {
                    path.Replace(virt, virtualToRealPlace[virt]);
                }
            }
            return(paths);
        }
Esempio n. 3
0
 public TravelWorld(TravelWorld travelWorld)
 {
     this._waterPlaces = new HashSet <int>(travelWorld._waterPlaces);
     this._fireWays    = new HashSet <TravelEdge>(travelWorld._fireWays);
     this._graph       = travelWorld._graph;
 }
Esempio n. 4
0
 public TravelWorld(TravelGraph travelGraph)
 {
     _graph = travelGraph;
 }
Esempio n. 5
0
 public void CalcCheapestCleanPaths()
 {
     _clearGraph = createWorldWithClearWays();
     _clearGraph.CalcCheapestPaths();
 }