private void GenerateClustersFromNnc()
        {
            PenaltyCluster = new Cluster();

            if (ClustersCount >= nncClusters.Count)
            {
                Clusters = nncClusters;
            }
            else
            {
                Clusters = new List<Cluster>();

                List<Cluster> newClusters = new List<Cluster>();
                newClusters.AddRange(nncClusters);

                for (int i = 0; i != ClustersCount; i++)
                {
                    int index = TaskController.Rnd.Next(newClusters.Count);
                    Clusters.Add(newClusters[index]);
                    newClusters.RemoveAt(index);
                }

                foreach (Cluster newCluster in newClusters)
                {
                    PenaltyCluster.Merge(newCluster);
                }
            }

            foreach (Cluster cluster in Clusters)
            {
                cluster.Depot = Depot;
            }
        }
예제 #2
0
 // массив байт => массив бит
 public static bool[] BytesToBits(byte[] source)
 {
     List<bool> result = new List<bool>();
     foreach (byte b in source)
     {
         result.AddRange(ByteToEightBits(b));
     }
     return result.ToArray();
 }
예제 #3
0
        public Node(Node node)
        {
            Id = node.Id;
            Type = node.Type;
            ScreenPosition = node.ScreenPosition;
            RealPosition = node.RealPosition;
            Volume = node.Volume;

            Connections = new List<Connection>();
            Connections.AddRange(node.Connections);
        }
        public override List<Node> PrepareToDraw(System.Drawing.Color connectionsColor)
        {
            List<Node> drawingNodes = new List<Node>();
            drawingNodes.AddRange(base.PrepareToDraw(connectionsColor));

            foreach (Node node in PenaltyCluster.Nodes)
            {
                node.DisconnectFromAll();
                drawingNodes.Add(node);
            }

            return drawingNodes;
        }
예제 #5
0
        protected override List<Node> GenerateClusters(List<Node> nodesForClusters, Node _depot)
        {
            this.Depot = _depot;

            while (nodesForClusters.Count != 0)
            {
                bool b = false;

                for (int i = 0; i != Clusters.Count; i++)
                {
                    if (nodesForClusters.Count == 0)
                        break;

                    int index = TaskController.Rnd.Next(nodesForClusters.Count);

                    if (Clusters[i].Volume + nodesForClusters[index].Volume <= Clusters[i].CapacityLimit)
                    {
                        Clusters[i].AddNode(nodesForClusters[index]);
                        nodesForClusters.RemoveAt(index);
                        b = true;
                    }
                }

                if (!b && Clusters.Count == ClustersCount)
                {
                    break;
                }

                if (!b)
                {
                    AddCluster();
                }
            }

            List<Node> remainingNodes = new List<Node>();
            remainingNodes.AddRange(nodesForClusters);

            return remainingNodes;
        }
예제 #6
0
        public void Calculate(int scoutsCount, int goodSitesCount, int bestSitesCount, int neighboursForGoodSites, int neighboursForBestSites)
        {
            values = new List<double>();
            colonies = new List<BeesColony>();

            foreach (Cluster cluster in clusters)
            {
                if (cluster.Nodes.Count == 0)
                {
                    continue;
                }

                BeesColony colony = new BeesColony();

                colony.Problem = BeesColony.ProblemType.VRP_TSP;
                colony.ClustersCount = 1;
                colony.IsCalcLastChange = true;

                colony.ScoutsCount = scoutsCount;
                colony.GoodSitesCount = goodSitesCount;
                colony.BestSitesCount = bestSitesCount;
                colony.NeighboursForGoodSites = neighboursForGoodSites;
                colony.NeighboursForBestSites = neighboursForBestSites;

                List<Node> colonyNodes = new List<Node>();
                colonyNodes.AddRange(cluster.Nodes);

                if (cluster.Depot != null)
                {
                    colonyNodes.Add(cluster.Depot);
                }

                colony.SetNodes(colonyNodes);
                colony.CreateSites();
                colony.IterateToStop();

                values.Add(colony.Value);
                colonies.Add(colony);
            }

            Stop();
        }
예제 #7
0
        public override void DrawNodes()
        {
            List<Node> drawingNodes = new List<Node>();

            foreach (Cluster cluster in clusters)
            {
                drawingNodes.AddRange(cluster.GetDrawingNodes(Color.LightGray));
            }

            for (int i = 0; i != colonies.Count; i++)
            {
                drawingNodes.AddRange(colonies[i].BestSite.PrepareToDraw(TaskController.GetDrawingColor(i)));
            }

            if (notClusteredNodes != null)
            {
                drawingNodes.AddRange(notClusteredNodes);
            }

            TaskController.DrawNodes(drawingNodes);
        }
        protected void FormAllClusters()
        {
            allClusters = new List<Cluster>();
            allClusters.AddRange(Clusters);
            allClusters.Add(PenaltyCluster);

            NotClusteredNodes = PenaltyCluster.Nodes;
        }
        protected override void GoToNeighbour(Site site)
        {
            SiteClusteringCvrpp siteClusteringCvrpp = site as SiteClusteringCvrpp;

            Clusters = new List<Cluster>();
            Clusters.AddRange(siteClusteringCvrpp.Clusters);

            kilometerCost = siteClusteringCvrpp.kilometerCost;
            PenaltyCluster = new Cluster(siteClusteringCvrpp.PenaltyCluster);

            FormAllClusters();
        }
예제 #10
0
 protected override void GoToNeighbour(Site site)
 {
     Clusters = new List<Cluster>();
     Clusters.AddRange((site as SiteClusteringVrp).Clusters);
 }
예제 #11
0
        protected virtual List<Node> GenerateClusters(List<Node> nodesForClusters, Node _depot)
        {
            for (int i = 0; i != ClustersCount; i++)
            {
                Clusters.Add(new Cluster());
                Clusters[i].Depot = _depot;

                int nodeIndex = TaskController.Rnd.Next(nodesForClusters.Count);
                Clusters[i].AddNode(nodesForClusters[nodeIndex]);
                nodesForClusters.RemoveAt(nodeIndex);
            }

            foreach (Node node in nodesForClusters)
            {
                if (node.Type == Node.NodeType.Consumer)
                {
                    int clusterIndex = TaskController.Rnd.Next(Clusters.Count);
                    Clusters[clusterIndex].AddNode(node);
                }
            }

            List<Node> remainingNodes = new List<Node>();
            remainingNodes.AddRange(nodesForClusters);

            return remainingNodes;
        }
예제 #12
0
        public override List<Node> PrepareToDraw(Color connectionsColor)
        {
            DrawingNodes = new List<Node>();

            foreach (Cluster cluster in Clusters)
            {
                DrawingNodes.AddRange(cluster.GetDrawingNodes(Color.LightGray));
            }

            Node depot = Clusters[0].Depot;

            if (depot != null)
            {
                DrawingNodes.Add(depot);
            }

            return DrawingNodes;
        }