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; } }
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(); } }
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); }
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(); }
// массив байт => массив бит 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]; } }
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; }
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>(); }
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])); } }
static TaskController() { Nodes = new List<Node>(); drawnNodes = new List<List<Node>>(); lastFileName = ""; Algorithm = null; MinVolume = int.MaxValue; MaxVolume = int.MinValue; }
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(); }
protected ClusteringAlgorithm(List<Node> nodes, int clustersCount) : this(nodes) { ClustersCount = clustersCount; Clusters = new List<Cluster>(); for (int i = 0; i != ClustersCount; i++) { AddCluster(); } }
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>(); }
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 void CreateSites() { sites = new List<Site>(); Site.IsStartingInitialized = false; CreateNewSite().StartingInitialize(); for (int i = 0; i != ScoutsCount; i++) { sites.Add(CreateNewSite()); } }
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; }
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; }
/// <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; } }
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]); }
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(); }
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"); }
// массив бит => массив байт 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(); }
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]); }
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); }
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; }
public ClusteringToTsp(List<Cluster> clusters, List<Node> notClusteredNodes, double kilometerCost) { this.clusters = clusters; this.notClusteredNodes = notClusteredNodes; this.kilometerCost = kilometerCost; }
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); }