예제 #1
0
    //Creates a shopping list where one of the constraints is that the
    //total cost of all products must not exist a given budget.

    public Manifest MakeShoppingList(
        Manifest products,
        Func <Item, float, float> GetTransportCosts,
        Market market, float budget,
        LinearSpace fill_space = null,
        float fixed_costs      = 0,
        IEnumerable <Space> constraint_spaces = null,
        Func <Item, bool> CanTrade            = null)
    {
        if (constraint_spaces == null)
        {
            constraint_spaces = Enumerable.Empty <Space>();
        }
        constraint_spaces = constraint_spaces.Append(CreateBudgetSpace(
                                                         budget,
                                                         market,
                                                         (product, quantity) => GetTransportCosts(product, quantity)));

        return(MakeShoppingList(
                   products,
                   GetTransportCosts,
                   fill_space, fixed_costs,
                   constraint_spaces,
                   CanTrade));
    }
예제 #2
0
    //This combines the features of the above two methods.

    public Manifest MakeShoppingList(
        Manifest products,
        Func <Item, float, float> GetTransportCosts,
        Inventory inventory, Manifest junk,
        Market market, float budget,
        LinearSpace fill_space = null,
        float fixed_costs      = 0,
        IEnumerable <Space> constraint_spaces = null,
        Func <Item, bool> CanTrade            = null)
    {
        if (constraint_spaces == null)
        {
            constraint_spaces = Enumerable.Empty <Space>();
        }
        constraint_spaces = constraint_spaces.Append(
            CreateInventorySpace(inventory, junk));

        return(MakeShoppingList(
                   products,
                   GetTransportCosts,
                   market, budget,
                   fill_space, fixed_costs,
                   constraint_spaces,
                   CanTrade));
    }
예제 #3
0
        public void TestAlpha()
        {
            var a = new double[, ] {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };
            var b = new double[, ] {
                { 1, 0, 0 },
                { 0, 1, 0 },
                { 0, 0, 1 }
            };
            var c = new double[, ] {
                { 1, double.NaN, 2 },
                { 1, double.NaN, 2 },
                { 1, double.NaN, 2 }
            };

            LinearSpace <double> .op_Addition(a, b).Deco().Says("a + b");

            LinearSpace <double> .op_Division(a, b).Deco().Says("a / b");

            LinearSpace <double> .op_Multiply(a, c).Deco().Says("a * c");

            LinearSpace <double> .op_Division(a, c).Deco().Says("a / c");
        }
예제 #4
0
        public void VectorToVectorTest()
        {
            var a = new double[] { 1, 2, 3 };
            var b = new double[] { 10, 20, 30 };
            var z = LinearSpace <double> .op_Multiply(a, b);

            z.Deco().Says("vector-to-vector");
        }
예제 #5
0
        public void VectorToPointTest()
        {
            var a = new double[] { 1, 2, 3 };
            var b = 2D;
            var z = LinearSpace <double> .op_Multiply(a, b);

            z.Deco().Says("vector-to-point");
        }
예제 #6
0
        public void MatrixToPointTest()
        {
            var a = new double[, ] {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };
            var b = 2D;
            var z = LinearSpace <double> .op_Concatenate(a, b);

            z.Deco().Says("matrix-to-point");
        }
예제 #7
0
        public void MatrixToMatrixTest()
        {
            var a = new double[, ] {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };
            var b = new double[, ] {
                { 10, 0, 0 },
                { 0, 20, 0 },
                { 0, 0, 30 }
            };
            var z = LinearSpace <double> .op_Multiply(a, b);

            z.Deco().Says("matrix-to-matrix");
        }