Example #1
0
        public void TestExcelSampleInput()
        {
            XmlEngine e = new XmlEngine();
            var network = e.XmlFileToNetwork(
                XDocument.Load("../../TestNetworks/NewSampleInputs_orig.xml")
            );

            #region Check link information
            // Rely on order to match links.
            Link[] expectedLinks = new Link[]
            {
                new Link() { Distance = 681, MaxTrains = 10, FuelAdjustment = 1 },
                new Link() { Distance = 842, MaxTrains = 2, FuelAdjustment = 1.4 },

                new Link() { Distance = 681, MaxTrains = 10, FuelAdjustment = 1 },
                new Link() { Distance = 735, MaxTrains = 8, FuelAdjustment = 1.4 },
                new Link() { Distance = 367, MaxTrains = 10, FuelAdjustment = 1 },

                new Link() { Distance = 367, MaxTrains = 10, FuelAdjustment = 1 },
                new Link() { Distance = 689, MaxTrains = 12, FuelAdjustment = 1.4 },
                new Link() { Distance = 500, MaxTrains = 16, FuelAdjustment = 1 },

                new Link() { Distance = 500, MaxTrains = 16, FuelAdjustment = 1 },
                new Link() { Distance = 773, MaxTrains = 10, FuelAdjustment = 1.2 },

                new Link() { Distance = 842, MaxTrains = 2, FuelAdjustment = 1.4 },
                new Link() { Distance = 735, MaxTrains = 8, FuelAdjustment = 1.4 },
                new Link() { Distance = 689, MaxTrains = 12, FuelAdjustment = 1.4 },
                new Link() { Distance = 773, MaxTrains = 10, FuelAdjustment = 1.2 },
            };
            int linkI = 0;
            foreach(var l in network.Links)
            {
                double actualDist = l.Distance;
                double expectedDist = expectedLinks[linkI].Distance;

                Assert.IsTrue(ApproxEqual(actualDist, expectedDist, DistanceAllowableError));

                Assert.AreEqual(l.MaxTrains, expectedLinks[linkI].MaxTrains);
                Assert.AreEqual(l.FuelAdjustment, expectedLinks[linkI].FuelAdjustment);

                linkI++;
            }
            #endregion
        }
        public void TestNewExample4()
        {
            XmlEngine e = new XmlEngine();
            var network = e.XmlFileToNetwork(
                XDocument.Load("../../TestNetworks/new_example4.xml")
            );

            // Assign 1-based IDs to check against the excel documents.
            for(int i = 0; i < network.Nodes.Count; i++)
                network.Nodes.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Links.Count; i++)
                network.Links.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Orders.Count; i++)
                network.Orders.ElementAt(i).ID = i + 1;

            network.Optimize();

            #region Expected values
            var expectedNodeDec = TranslateToNodes(new Dictionary<string, Dictionary<string, int>>()
                {
                    {"LAX",
                        new Dictionary<string, int>(){
                            {"LAX>DEN", 560 },
                            {"LAX>PHX", 440 },
                            {"DEN>LAX", 0 },
                            {"DEN>PHX", 0 },
                            {"PHX>LAX", 0 },
                            {"PHX>DEN", 35 },
                        }
                    },
                    {"DEN",
                        new Dictionary<string, int>(){
                            {"LAX>DEN", 0 },
                            {"LAX>PHX", 0 },
                            {"DEN>LAX", 240 },
                            {"DEN>PHX", 560 },
                            {"PHX>LAX", 60 },
                            {"PHX>DEN", 0 },
                        }
                    },
                    {"PHX",
                        new Dictionary<string, int>(){
                            {"LAX>DEN", 0 },
                            {"LAX>PHX", 0 },
                            {"DEN>LAX", 0 },
                            {"DEN>PHX", 0 },
                            {"PHX>LAX", 100 },
                            {"PHX>DEN", 100 },
                        }
                    }
                }, network);
            var expectedLinkDec = TranslateToLinks(new Dictionary<string, int>()
                {
                    {"LAX>DEN", 7 },
                    {"LAX>PHX", 6 },
                    {"DEN>LAX", 3 },
                    {"DEN>PHX", 7 },
                    {"PHX>LAX", 2 },
                    {"PHX>DEN", 2 },
                }, network);
            #endregion

            OptimizationEngine oe = OptimizationEngine.getInstance();
            var optimization = oe.Optimize(network,
                new OptimizationEngine.OptimizationOptions());

            var op = optimization.ToOptimization();

            Assert.IsTrue(NodeDictionariesEqual(expectedNodeDec, optimization.flowDecisions));

            Assert.IsTrue(
                LinkDictionariesEqual(expectedLinkDec, optimization.locomotiveDecisions));

            Assert.AreEqual(9917500, optimization.totalCost);
        }
        public void TestNewNetwork()
        {
            XmlEngine e = new XmlEngine();
            var network = e.XmlFileToNetwork(
                XDocument.Load("../../TestNetworks/NewSampleInputs.xml")
            );

            // Assign 1-based IDs to maintain validity.
            for(int i = 0; i < network.Nodes.Count; i++)
                network.Nodes.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Links.Count; i++)
                network.Links.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Orders.Count; i++)
                network.Orders.ElementAt(i).ID = i + 1;

            OptimizationEngine oe = OptimizationEngine.getInstance();
            var optimization = oe.Optimize(network,
                new OptimizationEngine.OptimizationOptions());

            var op = optimization.ToOptimization();

            // Can't get the excel spreadsheet to agree even if I give it the optimizer's shipping
            // decisions and train numbers.
            Assert.AreEqual(3343246, optimization.totalCost);

            Assert.Inconclusive();
        }