public void RunTSP(TSPAlgorithm algorithm)
        {
            //LastTSPResult = null;
            LastRoute = null;
            IList <TNode> result = null;

            LastBenchmark = RunningTime.TestNow(() =>
            {
                switch (algorithm)
                {
                //case TSPAlgorithm.LKH:
                //    result = lkh.Solve(Nodes, costAnalyzer);
                //    break;
                case TSPAlgorithm.EAX:
                    var problem = new TSPProblem(0, costMatrix.Matrix);
                    LastRoute   = eax.Solve(problem);
                    break;
                    //case TSPAlgorithm.NN:
                    //    result = nearestNeighbor.Solve(Nodes, costAnalyzer);
                    //    break;
                    //case TSPAlgorithm.OLC:
                    //    result = oneLoopCheapestInsertion.Solve(Nodes, costByReference, costAnalyzer);
                    //    break;
                    //case TSPAlgorithm.RAI:
                    //    result = randomArbitraryInsertion.Solve(Nodes, costByReference, costAnalyzer);
                    //    break;
                }
            });

            //if (result != null)
            //    LastTSPResult = new TSPResult<TNode, double>(result);

            cluster_AfterIterationEvent(this, EventArgs.Empty);
        }
Exemple #2
0
        //
        // GET: /Plan/
        public ActionResult Index()
        {
            string[] listCities = new string[] { "Ho Chi Minh", "Bac Ninh", "Hanoi", "Da Nang" };

            int SIZE = listCities.Length;

            List <int> distances = new List <int>();

            for (int i = 0; i < SIZE - 1; i++)
            {
                for (int j = i + 1; j < SIZE; j++)
                {
                    // Transit directions
                    var transitDirectionRequest = new DirectionsRequest
                    {
                        Origin            = listCities[i] + " City, Vietnam",
                        Destination       = listCities[j] + " City, Vietnam",
                        TravelMode        = TravelMode.Driving,
                        OptimizeWaypoints = true
                    };

                    DirectionsResponse transitDirections = GoogleMaps.Directions.Query(transitDirectionRequest);

                    distances.Add(transitDirections.Routes.First().Legs.First().Distance.Value);
                }
            }

            int[,] cities = new int[SIZE, SIZE];

            int d = 0;

            for (int i = 0; i < SIZE - 1; i++)
            {
                for (int j = i + 1; j < SIZE; j++)
                {
                    cities[i, j] = distances[d];
                    cities[j, i] = distances[d];
                    d++;
                }
            }

            var oderedVisit = TSPAlgorithm.GTS(cities, SIZE);

            int x = 9;

            return(View());
        }