Ejemplo n.º 1
0
    internal static void PopulateByRow(IMPModeler model,
                                       INumVar[][] var,
                                       IRange[][]  rng)
    {
        //  First define the variables, three continuous and one integer
        double[]     xlb = { 0.0, 0.0, 0.0, 2.0 };
        double[]     xub = { 40.0,                      System.Double.MaxValue,
                             System.Double.MaxValue, 3.0 };
        NumVarType[] xt = { NumVarType.Float, NumVarType.Float,
                            NumVarType.Float, NumVarType.Int };
        INumVar[]    x = model.NumVarArray(4, xlb, xub, xt);
        var[0] = x;

        // Objective Function:  maximize x0 + 2*x1 + 3*x2 + x3
        double[] objvals = { 1.0, 2.0, 3.0, 1.0 };
        model.AddMaximize(model.ScalProd(x, objvals));

        // Three constraints
        rng[0] = new IRange[3];
        // - x0 + x1 + x2 + 10*x3 <= 20
        rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
                                          model.Prod(1.0, x[1]),
                                          model.Prod(1.0, x[2]),
                                          model.Prod(10.0, x[3])), 20.0);
        // x0 - 3*x1 + x2 <= 30
        rng[0][1] = model.AddLe(model.Sum(model.Prod(1.0, x[0]),
                                          model.Prod(-3.0, x[1]),
                                          model.Prod(1.0, x[2])), 30.0);
        // x1 - 3.5*x3 = 0
        rng[0][2] = model.AddEq(model.Sum(model.Prod(1.0, x[1]),
                                          model.Prod(-3.5, x[3])), 0.0);
    }
Ejemplo n.º 2
0
    internal static void PopulateByColumn(IMPModeler model,
                                          INumVar[][] var,
                                          IRange[][] rng)
    {
        IObjective obj = model.AddMaximize();

        rng[0]    = new IRange[2];
        rng[0][0] = model.AddRange(-System.Double.MaxValue, 20.0, "c1");
        rng[0][1] = model.AddRange(-System.Double.MaxValue, 30.0, "c2");

        IRange r0 = rng[0][0];
        IRange r1 = rng[0][1];

        var[0]    = new INumVar[3];
        var[0][0] = model.NumVar(model.Column(obj, 1.0).And(
                                     model.Column(r0, -1.0).And(
                                         model.Column(r1, 1.0))),
                                 0.0, 40.0, "x1");
        var[0][1] = model.NumVar(model.Column(obj, 2.0).And(
                                     model.Column(r0, 1.0).And(
                                         model.Column(r1, -3.0))),
                                 0.0, System.Double.MaxValue, "x2");
        var[0][2] = model.NumVar(model.Column(obj, 3.0).And(
                                     model.Column(r0, 1.0).And(
                                         model.Column(r1, 1.0))),
                                 0.0, System.Double.MaxValue, "x3");
    }
Ejemplo n.º 3
0
   internal static void PopulateByRow (IMPModeler  model,
                                       INumVar[][] var,
                                       IRange[][]  rng) {
      //  First define the variables, three continuous and one integer
      double[]        xlb = {0.0, 0.0, 0.0, 2.0};
      double[]        xub = {40.0, System.Double.MaxValue,
                                   System.Double.MaxValue, 3.0};
      NumVarType[] xt  = {NumVarType.Float, NumVarType.Float,
                          NumVarType.Float, NumVarType.Int};
      INumVar[]     x  = model.NumVarArray(4, xlb, xub, xt);
      var[0] = x;

      // Objective Function:  maximize x0 + 2*x1 + 3*x2 + x3
      double[] objvals = {1.0, 2.0, 3.0, 1.0};
      model.AddMaximize(model.ScalProd(x, objvals));

      // Three constraints
      rng[0] = new IRange[3];
      // - x0 + x1 + x2 + 10*x3 <= 20
      rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
                                        model.Prod( 1.0, x[1]),
                                        model.Prod( 1.0, x[2]),
                                        model.Prod(10.0, x[3])), 20.0);
      // x0 - 3*x1 + x2 <= 30
      rng[0][1] = model.AddLe(model.Sum(model.Prod( 1.0, x[0]),
                                        model.Prod(-3.0, x[1]),
                                        model.Prod( 1.0, x[2])), 30.0);
      // x1 - 3.5*x3 = 0
      rng[0][2] = model.AddEq(model.Sum(model.Prod( 1.0, x[1]),
                                        model.Prod(-3.5, x[3])), 0.0);
   }
Ejemplo n.º 4
0
 internal static void PopulateByRow(IMPModeler  model,
                                    INumVar[][] var,
                                    IRange[][]  rng) {
    double[] lb = {0.0, 0.0, 0.0};
    double[] ub = {40.0, System.Double.MaxValue, System.Double.MaxValue};
    var[0] = model.NumVarArray(3, lb, ub);
  
    double[] objvals = {1.0, 2.0, 3.0};
    model.AddMaximize(model.ScalProd(var[0], objvals));
  
    rng[0] = new IRange[2];
    rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, var[0][0]),
                                      model.Prod( 1.0, var[0][1]),
                                      model.Prod( 1.0, var[0][2])), 20.0);
    rng[0][1] = model.AddLe(model.Sum(model.Prod( 1.0, var[0][0]),
                                      model.Prod(-3.0, var[0][1]),
                                      model.Prod( 1.0, var[0][2])), 30.0);
 }
Ejemplo n.º 5
0
    internal static void PopulateByRow(IMPModeler model,
                                       INumVar[][] var,
                                       IRange[][]  rng)
    {
        double[] lb = { 0.0, 0.0, 0.0 };
        double[] ub = { 40.0, System.Double.MaxValue, System.Double.MaxValue };
        var[0] = model.NumVarArray(3, lb, ub);

        double[] objvals = { 1.0, 2.0, 3.0 };
        model.AddMaximize(model.ScalProd(var[0], objvals));

        rng[0]    = new IRange[2];
        rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, var[0][0]),
                                          model.Prod(1.0, var[0][1]),
                                          model.Prod(1.0, var[0][2])), 20.0);
        rng[0][1] = model.AddLe(model.Sum(model.Prod(1.0, var[0][0]),
                                          model.Prod(-3.0, var[0][1]),
                                          model.Prod(1.0, var[0][2])), 30.0);
    }
Ejemplo n.º 6
0
    internal static ILPMatrix PopulateByRow(IMPModeler model)
    {
        ILPMatrix lp = model.AddLPMatrix();

        double[]  lb = { 0.0, 0.0, 0.0 };
        double[]  ub = { 40.0, System.Double.MaxValue, System.Double.MaxValue };
        INumVar[] x  = model.NumVarArray(model.ColumnArray(lp, 3), lb, ub);

        double[]   lhs = { -System.Double.MaxValue, -System.Double.MaxValue };
        double[]   rhs = { 20.0, 30.0 };
        double[][] val = { new double[] { -1.0,  1.0, 1.0 },
                           new double[] {  1.0, -3.0, 1.0 } };
        int[][]    ind = { new int[] { 0, 1, 2 },
                           new int[] { 0, 1, 2 } };
        lp.AddRows(lhs, rhs, ind, val);

        double[] objvals = { 1.0, 2.0, 3.0 };
        model.AddMaximize(model.ScalProd(x, objvals));

        return(lp);
    }
Ejemplo n.º 7
0
    // The following methods all populate the problem with data for the following
    // linear program:
    //
    //    Maximize
    //     x1 + 2 x2 + 3 x3
    //    Subject To
    //     - x1 + x2 + x3 <= 20
    //     x1 - 3 x2 + x3 <= 30
    //    Bounds
    //     0 <= x1 <= 40
    //    End
    //
    // using the IMPModeler API

    internal static void PopulateByRow(IMPModeler model,
                                       INumVar[][] var,
                                       IRange[][] rng)
    {
        double[]  lb      = { 0.0, 0.0, 0.0 };
        double[]  ub      = { 40.0, System.Double.MaxValue, System.Double.MaxValue };
        string[]  varname = { "x1", "x2", "x3" };
        INumVar[] x       = model.NumVarArray(3, lb, ub, varname);
        var[0] = x;

        double[] objvals = { 1.0, 2.0, 3.0 };
        model.AddMaximize(model.ScalProd(x, objvals));

        rng[0]    = new IRange[2];
        rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
                                          model.Prod(1.0, x[1]),
                                          model.Prod(1.0, x[2])), 20.0, "c1");
        rng[0][1] = model.AddLe(model.Sum(model.Prod(1.0, x[0]),
                                          model.Prod(-3.0, x[1]),
                                          model.Prod(1.0, x[2])), 30.0, "c2");
    }
Ejemplo n.º 8
0
    internal static void PopulateByRow(IMPModeler model,
                                       INumVar[][] var,
                                       IRange[][]  rng)
    {
        // Define the variables one-by-one
        INumVar[] x = new INumVar[4];
        x[0]   = model.NumVar(0.0, 40.0, "x0");
        x[1]   = model.IntVar(0, System.Int32.MaxValue, "x1");
        x[2]   = model.IntVar(0, System.Int32.MaxValue, "x2");
        x[3]   = model.IntVar(2, 3, "x3");
        var[0] = x;

        // Objective Function
        model.AddMaximize(model.Sum(model.Prod(1.0, x[0]),
                                    model.Prod(2.0, x[1]),
                                    model.Prod(3.0, x[2]),
                                    model.Prod(1.0, x[3])));

        // Define three constraints one-by-one
        rng[0]    = new IRange[3];
        rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
                                          model.Prod(1.0, x[1]),
                                          model.Prod(1.0, x[2]),
                                          model.Prod(10.0, x[3])),
                                20.0, "rng0");
        rng[0][1] = model.AddLe(model.Sum(model.Prod(1.0, x[0]),
                                          model.Prod(-3.0, x[1]),
                                          model.Prod(1.0, x[2])),
                                30.0, "rng1");
        rng[0][2] = model.AddEq(model.Sum(model.Prod(1.0, x[1]),
                                          model.Prod(-3.5, x[3])),
                                0, "rng2");

        // add special ordered set of type 1
        INumVar[] sosvars    = { x[2], x[3] };
        double[]  sosweights = { 25.0, 18.0 };
        model.AddSOS1(sosvars, sosweights);
    }
Ejemplo n.º 9
0
 internal static ILPMatrix PopulateByRow(IMPModeler model) {
    ILPMatrix lp = model.AddLPMatrix();
  
    double[]  lb = {0.0, 0.0, 0.0};
    double[]  ub = {40.0, System.Double.MaxValue, System.Double.MaxValue};
    INumVar[] x  = model.NumVarArray(model.ColumnArray(lp, 3), lb, ub);
  
    double[]   lhs = {-System.Double.MaxValue, -System.Double.MaxValue};
    double[]   rhs = {20.0, 30.0};
    double[][] val = {new double[] {-1.0,  1.0,  1.0},
                      new double[] { 1.0, -3.0,  1.0}};
    int[][]    ind = {new int[] {0, 1, 2},
                      new int[] {0, 1, 2}};
    lp.AddRows(lhs, rhs, ind, val);
  
    double[] objvals = {1.0, 2.0, 3.0};
    model.AddMaximize(model.ScalProd(x, objvals));
  
    return (lp);
 }
Ejemplo n.º 10
0
   internal static void PopulateByColumn(IMPModeler model,
                                         INumVar[][] var,
                                         IRange[][] rng) {
      IObjective obj = model.AddMaximize();

      rng[0] = new IRange[2];
      rng[0][0] = model.AddRange(-System.Double.MaxValue, 20.0, "c1");
      rng[0][1] = model.AddRange(-System.Double.MaxValue, 30.0, "c2");

      IRange r0 = rng[0][0];
      IRange r1 = rng[0][1];

      var[0] = new INumVar[3];
      var[0][0] = model.NumVar(model.Column(obj,  1.0).And(
                               model.Column(r0,  -1.0).And(
                               model.Column(r1,   1.0))),
                               0.0, 40.0, "x1");
      var[0][1] = model.NumVar(model.Column(obj,  2.0).And(
                               model.Column(r0,   1.0).And(
                               model.Column(r1,  -3.0))),
                               0.0, System.Double.MaxValue, "x2");
      var[0][2] = model.NumVar(model.Column(obj,  3.0).And(
                               model.Column(r0,   1.0).And(
                               model.Column(r1,   1.0))),
                               0.0, System.Double.MaxValue, "x3");
   }
Ejemplo n.º 11
0
   // The following methods all populate the problem with data for the following
   // linear program:
   //
   //    Maximize
   //     x1 + 2 x2 + 3 x3
   //    Subject To
   //     - x1 + x2 + x3 <= 20
   //     x1 - 3 x2 + x3 <= 30
   //    Bounds
   //     0 <= x1 <= 40
   //    End
   //
   // using the IMPModeler API

   internal static void PopulateByRow(IMPModeler model,
                                      INumVar[][] var,
                                      IRange[][] rng) {
      double[]  lb      = {0.0, 0.0, 0.0};
      double[]  ub      = {40.0, System.Double.MaxValue, System.Double.MaxValue};
      string[]  varname = {"x1", "x2", "x3"};
      INumVar[] x       = model.NumVarArray(3, lb, ub, varname);
      var[0] = x;

      double[] objvals = {1.0, 2.0, 3.0};
      model.AddMaximize(model.ScalProd(x, objvals));

      rng[0] = new IRange[2];
      rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
                                        model.Prod( 1.0, x[1]),
                                        model.Prod( 1.0, x[2])), 20.0, "c1");
      rng[0][1] = model.AddLe(model.Sum(model.Prod( 1.0, x[0]),
                                        model.Prod(-3.0, x[1]),
                                        model.Prod( 1.0, x[2])), 30.0, "c2");
   }
Ejemplo n.º 12
0
   internal static void PopulateByRow (IMPModeler  model,
                                       INumVar[][] var,
                                       IRange[][]  rng) {

      // Define the variables one-by-one
      INumVar[] x = new INumVar[4];
      x[0] = model.NumVar(0.0, 40.0, "x0");
      x[1] = model.IntVar(0, System.Int32.MaxValue, "x1");
      x[2] = model.IntVar(0, System.Int32.MaxValue, "x2");
      x[3] = model.IntVar(2, 3, "x3");
      var[0] = x;
    
      // Objective Function
      model.AddMaximize(model.Sum(model.Prod( 1.0, x[0]),
                                  model.Prod( 2.0, x[1]),
                                  model.Prod( 3.0, x[2]),
                                  model.Prod( 1.0, x[3])));
    
      // Define three constraints one-by-one 
      rng[0] = new IRange[3];
      rng[0][0] = model.AddLe(model.Sum(model.Prod(-1.0, x[0]),
                                        model.Prod( 1.0, x[1]),
                                        model.Prod( 1.0, x[2]),
                                        model.Prod(10.0, x[3])),
                              20.0, "rng0");
      rng[0][1] = model.AddLe(model.Sum(model.Prod( 1.0, x[0]),
                                        model.Prod(-3.0, x[1]),
                                        model.Prod( 1.0, x[2])),
                              30.0, "rng1");
      rng[0][2] = model.AddEq(model.Sum(model.Prod( 1.0, x[1]),
                                        model.Prod(-3.5, x[3])),
                              0, "rng2");
    
      // add special ordered set of type 1
      INumVar[] sosvars    = {x[2], x[3]};
      double[]  sosweights = {25.0, 18.0};
      model.AddSOS1(sosvars, sosweights);
   }