public IterationStep(List <ACOCity> path, TSPGraph <ACOCity, ACODistance> graph)
 {
     pathState  = new List <ACOCity>();
     graphState = new TSPGraph <ACOCity, ACODistance>();
     CopyGraph(graph);
     CopyPath(path);
 }
Exemplo n.º 2
0
        public void SetGraph(TSPGraph <ACOCity, ACODistance> graph)
        {
            _OldNodes = new List <Node>(_Nodes);
            ClearGraph();

            foreach (ACOCity city in graph.GetCities())
            {
                AddNewNode(city, graph.GetCities());
            }
        }
        private void InitAnts(TSPGraph <ACOCity, ACODistance> graph)
        {
            _Ants.Clear();
            foreach (ACOCity c in graph.GetCities())
            {
                c.RemoveAnts();
            }

            for (int i = 0; i < _Props.AntsCount; i++)
            {
                _Ants.Add(new Ant(_Props, graph.GetCities()));
            }
        }
        private void CopyGraph(TSPGraph <ACOCity, ACODistance> graph)
        {
            foreach (ACOCity mainCity in graph.GetCities())
            {
                ACOCity copiedCity = (ACOCity)mainCity.Clone();


                for (int i = 0; i < graphState.GetCities().Count; i++)
                {
                    ACODistance dist = (ACODistance)((ACODistance)mainCity.GetDistanceTo(graph.GetCities()[i])).Clone();
                    copiedCity.Connect(graphState.GetCities()[i], dist);
                }

                graphState.AddCity(copiedCity);
            }
        }
        public List <ACOCity> GetOptimalPath(TSPGraph <ACOCity, ACODistance> graph)
        {
            iterationSteps = new List <IterationStep>();
            List <ACOCity> bestPath = null;

            InitAnts(graph);
            for (int i = 0; i < _Props.IterationsCount; i++)
            {
                List <List <ACOCity> > paths = FindPaths();
                bestPath = UpdatePathsData(paths, bestPath);
                iterationSteps.Add(new IterationStep(bestPath, graph));
                foreach (Ant ant in _Ants)
                {
                    ant.ClearMemory();
                }
            }
            return(bestPath);
        }
Exemplo n.º 6
0
 public GraphView()
 {
     InitializeComponent();
     _Nodes = new List <Node>();
     _Graph = new TSPGraph <ACOCity, ACODistance>();
 }