protected ClusteringAlgorithm(List<Node> nodes) { SetNodes(nodes); if (Depots.Count != 0) { Depot = Depots[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 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 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 void ConnectTo(Node node, Color color) { Connections.Add(new Connection {Color = color, ConnectedNode = node}); }
public void ConnectTo(Node node) { ConnectTo(node, Color.Black); }
protected override List<Node> GenerateClusters(List<Node> nodesForClusters, Node _depot) { Depot = _depot; return null; }
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; }
private static void DrawNode(Graphics g, Node node) { switch (node.Type) { case Node.NodeType.Consumer: int size = MaxVolume == MinVolume ? (ConsumerMaxSize + ConsumerMinSize) / 2 : Convert.ToInt32((ConsumerMaxSize - ConsumerMinSize) * (double)(node.Volume - MinVolume) / (double)(MaxVolume - MinVolume)) + ConsumerMinSize; g.FillEllipse(ConsumerBrush, (int)(node.ScreenPosition.x - size / 2.0), (int)(node.ScreenPosition.y - size / 2.0), size, size); break; case Node.NodeType.Depot: g.FillRectangle(DepotBrush, (int)(node.ScreenPosition.x - DepotSize / 2.0), (int)(node.ScreenPosition.y - DepotSize / 2.0), DepotSize, DepotSize); break; case Node.NodeType.Auxiliary: g.FillEllipse(AuxiliaryBrush, (int)(node.ScreenPosition.x - AuxiliarySize / 2.0), (int)(node.ScreenPosition.y - AuxiliarySize / 2.0), AuxiliarySize, AuxiliarySize); break; } }
public static void AddNodeAtScreen(Node.NodeType nodeType, int posX, int posY, int volume = 1, int fine = 0) { Node newNode = new Node(Nodes.Count, nodeType, posX, posY, posX, posY) {Volume = volume, Fine = fine}; Nodes.Add(newNode); if (!CheckVolume()) { DrawNode(graphicsForDraw, newNode); } else { DrawNodes(); } }
private void ConnectConsumerToDepot(Node node1, Node node2, Color connectionColor) { if (node1.Type != Node.NodeType.Depot) { node1.ConnectTo(node2, connectionColor); } else { node2.ConnectTo(node1, connectionColor); } }
private static double GetDistance(Node node1, Node node2) { return Math.Sqrt(Math.Pow(node1.RealPosition.x - node2.RealPosition.x, 2) + Math.Pow(node1.RealPosition.y - node2.RealPosition.y, 2)); }
public void AddNode(Node node) { Nodes.Add(node); nodesUpdated = true; }
public void RemoveNode(Node node) { Nodes.Remove(node); nodesUpdated = true; }
public List<Node> GetDrawingNodes(Color connectionsColor) { List<Node> drawingNodes = new List<Node>(); if (Nodes.Count == 0) { return drawingNodes; } Node center = new Node(-1, Node.NodeType.Auxiliary, (int)Center.x, (int)Center.y, Center.x, Center.y); foreach (Node node in Nodes) { center.ConnectTo(node, connectionsColor); drawingNodes.Add(node); } drawingNodes.Add(center); return drawingNodes; }