Example #1
0
        public routes(float[,] distanceList, List <int[]> paths)
        {
            this.routeList = new List <route>();
            for (int i = 0; i < paths.Count; i++)

            {
                route route = new route(distanceList, paths[i]);
                this.routeList.Add(route);
            }
            this.routeList = routeList.OrderBy(x => x.netdistance).ToList();
        }
Example #2
0
        public void bruteFindFastest(List <node> nodes, node startnode)
        {
            int[] nodeIDlist = new int[nodes.Count() - 1];
            float[,] distancelist = this.distanceList(nodes);
            int numperms = this.FactNum(nodes.Count() - 1);

            int[] fastestpath = new int[nodes.Count()];
            int[] currentpath = new int[nodes.Count()];
            route fastestroute;
            route currentroute;

            fastestpath[0] = startnode.id;
            currentpath[0] = startnode.id;
            int count = 0;

            for (int i = 0; i < nodes.Count(); i++)
            {
                if (nodes[i].id != startnode.id)
                {
                    nodeIDlist[count] = nodes[i].id;
                    count++;
                }
            }
            nodeIDlist.CopyTo(fastestpath, 1);
            fastestroute = new route(distancelist, fastestpath);

            for (int i = 0; i < numperms - 1; i++)
            {
                nodeIDlist = NextPermutation(nodeIDlist);
                nodeIDlist.CopyTo(currentpath, 1);
                currentroute = new route(distancelist, currentpath);

                if (currentroute.netdistance < fastestroute.netdistance)
                {
                    currentpath.CopyTo(fastestpath, 0);
                    fastestroute = new route(distancelist, fastestpath);
                }
            }
            fastestroute.printPath();
            Console.WriteLine("\nDistance:  " + fastestroute.netdistance);
            Console.WriteLine("Traveling from and back to Node# " + startnode.id);
        }