Exemple #1
0
        private void GenerateStartNode()
        {
            ShipmentNode shipmentNode = new ShipmentNode
            {
                Id   = 0,
                Type = ShipmentNodeType.Start
            };

            Nodes.Add(shipmentNode);
        }
Exemple #2
0
        private void GenerateLastNode(int id)
        {
            ShipmentNode shipmentNode = new ShipmentNode
            {
                Id   = id,
                Type = ShipmentNodeType.Finish
            };

            Nodes.Add(shipmentNode);
        }
Exemple #3
0
        private void GenerateSolutionPaths(int solutionPaths, List <int> edgesBySolutionPath)
        {
            // hago - 2 xq el ultimo se lo voy a agregar al final. El 0 lo agrego si o si.
            Randomizer nodeRandomizer = Randomizer.New(Nodes.Count - 2, 1, false);

            for (int i = solutionPaths - 1; i >= 0; i--)
            {
                nodeRandomizer.Restart();
                int           pathLength    = edgesBySolutionPath[i];
                ShipmentsPath shipmentsPath = new ShipmentsPath
                {
                    // Agrego el primero
                    // la cantidad de nodos es la de aristas + 1
                    NodesList = new List <ShipmentNode>(pathLength + 1)
                    {
                        Nodes[0]
                    }
                };
                // es -3 xq el 0 y el ultimo ya estan fijos
                for (int j = 1; j <= shipmentsPath.NodesList.Capacity - 2; j++)
                {
                    ShipmentNode shipmentNode = Nodes[nodeRandomizer.Next()];

                    while (shipmentsPath.NodesList.Exists(e => e.Id == shipmentNode.Id) || GetEdgesByIdNode(shipmentNode.Id).Count > 2)
                    {
                        shipmentNode = Nodes[nodeRandomizer.Next()];
                    }
                    shipmentsPath.NodesList.Add(shipmentNode);

                    if (!ExistsEdge(shipmentsPath.NodesList[j - 1].Id, shipmentsPath.NodesList[j].Id))
                    {
                        ShipmentEdge edge = new ShipmentEdge();
                        edge.IdNodeA = shipmentsPath.NodesList[j - 1].Id;
                        edge.IdNodeB = shipmentsPath.NodesList[j].Id;
                        Edges.Add(edge);
                    }
                }
                // Agrego el ultimo
                shipmentsPath.NodesList.Add(Nodes[Nodes.Count - 1]);
                ShipmentEdge lastEdge = new ShipmentEdge();
                lastEdge.IdNodeA = shipmentsPath.NodesList[shipmentsPath.NodesList.Count - 2].Id;
                lastEdge.IdNodeB = shipmentsPath.NodesList[shipmentsPath.NodesList.Count - 1].Id;
                Edges.Add(lastEdge);

                _solutionPaths.Add(shipmentsPath);
            }
        }
Exemple #4
0
        private void GenerateNodes(int totalNodes)
        {
            Nodes.Clear();
            GenerateStartNode();
            Randomizer nodeRandomizer = Randomizer.New(NODES - 1);

            nodeRandomizer.ExcludeNumbers(new List <int>()
            {
                0
            });
            for (int i = totalNodes - 3; i >= 0; i--)
            {
                ShipmentNode shipmentNode = new ShipmentNode
                {
                    Id   = nodeRandomizer.Next(),
                    Type = ShipmentNodeType.Other
                };
                Nodes.Add(shipmentNode);
            }
            GenerateLastNode(nodeRandomizer.Next());
        }
Exemple #5
0
 public bool Equals(ShipmentNode otherNode)
 {
     return(Id == otherNode.Id);
 }