예제 #1
0
        public void AddParams()
        {
            var set = new MemorySet("IJ", 2);

            set.AddElement("i1", "j1");
            set.AddElement("i1", "j1");
            Assert.AreEqual(1, set.Elements.Count);
        }
예제 #2
0
        public void AddDuplicate()
        {
            var set = new MemorySet("I", 1);

            set.AddElement("i1");
            set.AddElement("i1");
            Assert.AreEqual(1, set.Elements.Count);
        }
예제 #3
0
        public void AddInvalidDimension2()
        {
            var set     = new MemorySet("I", 1);
            var gamsKey = new GamsKey("i1", "j2");

            Assert.ThrowsException <ArgumentException>(() => set.AddElement(gamsKey));
        }
예제 #4
0
        public static MemoryDatabase CreateTransportDatabase()
        {
            var setI = new MemorySet("I", 1, "canning plants");

            setI.AddElement("seattle");
            setI.AddElement("san-diego");

            var setJ = new MemorySet("J", 1, "markets");

            setJ.AddElement("new-york");
            setJ.AddElement("chicago");
            setJ.AddElement("topeka");

            var parameterA = new MemoryParameter("a", 1, "capacity of plant i in cases");

            parameterA.AddRecord(350, "seattle");
            parameterA.AddRecord(600, "san-diego");

            var parameterB = new MemoryParameter("b", 1, "demand at market j in cases");

            parameterB.AddRecord(325, "new-york");
            parameterB.AddRecord(300, "chicago");
            parameterB.AddRecord(275, "topeka");

            var parameterD = new MemoryParameter("d", 2, "distance in thousands of miles");

            parameterD.AddRecord(2.5, new GamsKey("seattle", "new-york"));
            parameterD.AddRecord(1.7, new GamsKey("seattle", "chicago"));
            parameterD.AddRecord(1.8, new GamsKey("seattle", "topeka"));
            parameterD.AddRecord(2.5, new GamsKey("san-diego", "new-york"));
            parameterD.AddRecord(1.8, new GamsKey("san-diego", "chicago"));
            parameterD.AddRecord(1.4, new GamsKey("san-diego", "topeka"));

            var parameterF = new MemoryParameter("f", 0, "freight in dollars per case per thousand miles");

            parameterF.AddRecord(90, new GamsKey());

            var parameterC = new MemoryParameter("c", 2, "transport cost in thousands of dollars per case");

            foreach (var distance in parameterD.Records)
            {
                parameterC.AddRecord(distance.Value * parameterF.Records[new GamsKey()], distance.Key);
            }

            var variableX = new MemoryVariable("x", 2, MemoryVariableTypes.Positive, "shipment quantities in cases");

            foreach (var i in setI.Elements)
            {
                foreach (var j in setJ.Elements)
                {
                    var gamsKey        = new GamsKey(i.Keys.Single(), j.Keys.Single());
                    var variableValues = new VariableValues(0, 0);
                    variableX.AddRecord(gamsKey, variableValues);
                }
            }

            var variableZ = new MemoryVariable("z", 0, MemoryVariableTypes.Free, "total transportation costs in thousands of dollars");

            variableZ.AddRecord(new GamsKey(), new VariableValues());

            var sets = new MemorySet[]
            {
                setI,
                setJ
            };

            var parameters = new MemoryParameter[]
            {
                parameterA,
                parameterB,
                parameterC,
                parameterD,
                parameterF,
            };

            var variables = new MemoryVariable[]
            {
                variableX,
                variableZ
            };
            var memoryDatabase = new MemoryDatabase("transport", sets, parameters, variables);

            return(memoryDatabase);
        }
예제 #5
0
        public void AddInvalidDimension1()
        {
            var set = new MemorySet("I", 2);

            Assert.ThrowsException <ArgumentException>(() => set.AddElement("i1"));
        }