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 SiteClusteringVrp(List<Node> nodes, int clustersCount)
            : base(nodes)
        {
            Clusters = new List<Cluster>();
            ClustersCount = clustersCount;

            GenerateClusters();
        }
 public SiteClusteringCvrppNnc(List<Node> nodes, int capacityLimit, int clustersCount, double kilometerCost)
     : base(nodes, capacityLimit, clustersCount, kilometerCost)
 {
     if (IsStartingInitialized)
     {
         GenerateClustersFromNnc();
     }
 }
Пример #4
0
 public SiteVrpTsp(List<Node> nodes, int depotsCount, int consumersCount, int clustersCount)
     : base(nodes)
 {
     this.prices = GeneratePricesByPositions(nodes, depotsCount, consumersCount);
     this.depotsCount = depotsCount;
     this.consumersCount = consumersCount;
     GenerateSequence(depotsCount, clustersCount, consumersCount);
 }
Пример #5
0
        public SiteClusteringCvrp(List<Node> nodes, int capacityLimit, int clustersCount = int.MaxValue)
            : base(nodes)
        {
            Clusters = new List<Cluster>();
            this.CapacityLimit = capacityLimit;
            this.ClustersCount = clustersCount;

            RemainingNodes = GenerateClusters();
        }
Пример #6
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();
 }
        protected ClusteringAlgorithm(List<Node> nodes)
        {
            SetNodes(nodes);

            if (Depots.Count != 0)
            {
                Depot = Depots[0];
            }
        }
Пример #8
0
        protected Site(List<Node> nodes)
        {
            Nodes = new List<Node>();

            for (int i = 0; i != nodes.Count; i++)
            {
                Nodes.Add(nodes[i]);
            }
        }
        public NearestNeighbourChain(List<Node> nodes, int capacityLimit)
            : base(nodes)
        {
            this.capacityLimit = capacityLimit;

            GenerateClusters();

            lastReviewedCluster = -1;
        }
Пример #10
0
        public Node(int id, NodeType nodeType, int screenPosX, int screenPosY, double realPosX, double realPosY)
        {
            Id = id;
            Type = nodeType;
            ScreenPosition = new Point(screenPosX, screenPosY);
            RealPosition = new Point(realPosX, realPosY);

            Connections = new List<Connection>();
        }
Пример #11
0
        protected SiteClusteringVrp(SiteClusteringVrp site)
            : base(site.Nodes)
        {
            Clusters = new List<Cluster>();

            for (int i = 0; i != site.Clusters.Count; i++)
            {
                Clusters.Add(new Cluster(site.Clusters[i]));
            }
        }
Пример #12
0
        static TaskController()
        {
            Nodes = new List<Node>();
            drawnNodes = new List<List<Node>>();
            lastFileName = "";
            Algorithm = null;

            MinVolume = int.MaxValue;
            MaxVolume = int.MinValue;
        }
Пример #13
0
        public SiteClusteringCvrpp(List<Node> nodes, int capacityLimit, int clustersCount, double kilometerCost)
            : base(nodes, capacityLimit, clustersCount)
        {
            PenaltyCluster = new Cluster();
            PenaltyCluster.AddNodes(RemainingNodes);

            this.kilometerCost = kilometerCost;

            FormAllClusters();
        }
Пример #14
0
        protected ClusteringAlgorithm(List<Node> nodes, int clustersCount)
            : this(nodes)
        {
            ClustersCount = clustersCount;
            Clusters = new List<Cluster>();

            for (int i = 0; i != ClustersCount; i++)
            {
                AddCluster();
            }
        }
Пример #15
0
        public Node()
        {
            Id = -1;
            Type = NodeType.Unknown;
            ScreenPosition = new Point(0, 0);
            RealPosition = new Point(0, 0);
            Volume = 0;
            Fine = 0;

            Connections = new List<Connection>();
        }
Пример #16
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);
        }
Пример #17
0
        public void CreateSites()
        {
            sites = new List<Site>();

            Site.IsStartingInitialized = false;
            CreateNewSite().StartingInitialize();

            for (int i = 0; i != ScoutsCount; i++)
            {
                sites.Add(CreateNewSite());
            }
        }
Пример #18
0
        public Cluster(Cluster cluster)
        {
            Nodes = new List<Node>();

            foreach (Node node in cluster.Nodes)
            {
                Nodes.Add(node);
            }

            Depot = cluster.Depot;
            CapacityLimit = cluster.CapacityLimit;
        }
        public override void StartingInitialize()
        {
            base.StartingInitialize();

            List<Node> consumers = (from node in Nodes
                                    where node.Type == Node.NodeType.Consumer
                                    select node).ToList();

            NearestNeighbourChain nnc = new NearestNeighbourChain(consumers, CapacityLimit);
            nnc.IterateToStop();

            nncClusters = nnc.Clusters;
        }
Пример #20
0
        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;
        }
Пример #21
0
 /// <summary>
 /// Deserializes workflow markup into an List object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output List object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out List obj, out System.Exception exception)
 {
     exception = null;
     obj = default(List);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
Пример #22
0
        public static bool ExchangeNodesInClusters(List<Cluster> clusters)
        {
            if (clusters.Count <= 1)
            {
                return false;
            }

            int i1 = TaskController.Rnd.Next(clusters.Count);
            int i2;

            do
            {
                i2 = TaskController.Rnd.Next(clusters.Count);
            } while (i2 == i1);

            return ExchangeNodesInClusters(clusters[i1], clusters[i2]);
        }
Пример #23
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();
        }
Пример #24
0
        public GeneralViewModel()
        {
            Boxes = new List<Box> { };
            FirstGroupButtons = new List<ToolBarButtonBase> { };

            FirstGroupButtons.Add(new ToolBarButtonBase(false, new BitmapImage(new Uri("Images/selectAndMove.png", UriKind.Relative)), "SelectAndMove"));
            FirstGroupButtons.Add(new ToolBarButtonBase(false, new BitmapImage(new Uri("Images/selectAndRotate.png", UriKind.Relative)), "SelectAndRotate"));

            SecondGroupButtons = new List<ToolBarButtonBase> { };
            SecondGroupButtons.Add(new ToolBarButtonBase(false, new BitmapImage(new Uri("Images/selectObject.png", UriKind.Relative)), "SelectObject"));

            BoxPropertiesVisibility = Visibility.Collapsed;
            BoxPropertiesImg = new BitmapImage(new Uri("Images/plus.png", UriKind.Relative));
            OnPropertyChanged("BoxPropertiesVisibility");
            OnPropertyChanged("BoxPropertiesImg");
            BoxListVisibility = Visibility.Collapsed;
            BoxListImg = new BitmapImage(new Uri("Images/plus.png", UriKind.Relative));
            OnPropertyChanged("BoxListVisibility");
            OnPropertyChanged("BoxListImg");
        }
Пример #25
0
 // массив бит => массив байт
 public static byte[] BitsToBytes(bool[] source)
 {
     List<byte> listOfBytes = new List<byte>();
     List<bool> listOfBools = source.ToList();
     try
     {
         do
         {
             bool[] eightBits = listOfBools.Take(8).ToArray();
             listOfBools.RemoveRange(0, 8);
             listOfBytes.Add(EightBitsToByte(eightBits));
         } while (listOfBools.Count != 0);
     }
     catch (ArgumentException)
     {
         listOfBools.AddRange(new bool[8 - listOfBools.Count]);
         bool[] eightBits = listOfBools.ToArray();
         listOfBytes.Add(EightBitsToByte(eightBits));
     }
     return listOfBytes.ToArray();
 }
Пример #26
0
        public static void MoveNodeFromOneClusterToAnother(List<Cluster> clusters)
        {
            if (clusters.Count <= 1)
            {
                return;
            }

            int c1;
            int c2;

            do
            {
                c1 = TaskController.Rnd.Next(clusters.Count);
            } while (clusters[c1].Nodes.Count <= 1);

            do
            {
                c2 = TaskController.Rnd.Next(clusters.Count);
            } while (c2 == c1);

            MoveNodeFromOneClusterToAnother(clusters[c1], clusters[c2]);
        }
Пример #27
0
        public override void DrawNodes()
        {
            List<Node> drawingNodes = new List<Node>();

            for (int i = 0; i != Clusters.Count; i++)
            {
                Cluster cluster = Clusters[i];

                if (cluster.Nodes.Count == 0)
                {
                    continue;
                }

                Node center = new Node(-1, Node.NodeType.Auxiliary, (int)Clusters[i].Center.x, (int)Clusters[i].Center.y, Clusters[i].Center.x, Clusters[i].Center.y);

                if (cluster.Nodes.Count == 0)
                {
                    drawingNodes.Add(center);
                    continue;
                }

                foreach (Node node in cluster.Nodes)
                {
                    center.ConnectTo(node, Color.LightGray);
                    drawingNodes.Add(node);
                }

                drawingNodes.Add(center);
            }

            Node depot = Clusters[0].Depot;

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

            TaskController.DrawNodes(drawingNodes);
        }
Пример #28
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;
        }
Пример #29
0
 public ClusteringToTsp(List<Cluster> clusters, List<Node> notClusteredNodes, double kilometerCost)
 {
     this.clusters = clusters;
     this.notClusteredNodes = notClusteredNodes;
     this.kilometerCost = kilometerCost;
 }
Пример #30
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);
        }