Decision Optimization

 View Only
Expand all | Collapse all

OPL mathematical programming

  • 1.  OPL mathematical programming

    Posted Thu May 14, 2009 10:48 AM

    Originally posted by: SystemAdmin


    [miso said:]

    Dear All,

    I have another, probably odd, question for the forum regarding coding or programming in OPL. In order to make a problem statement more applicable to varying inputs: is it possible to suppress some constraints in reference to a given input variable?

    For example:
    An input value defines an array of decision variables a of the problem in the range of (1..InputValue). If the input value is 2 then there a two decision variables defined in array, and so on.

    Within the optimization problem one or more constraints then commonly include a set of variables in a loop.
    i.e.
    forall (i in 1..InputValue-1)
    forall (j in i+1..InputValue)
    a[i] + b >= a[j]; 

    Assuming then, that the input value could possibly also be 1, how could the coding of program still allow running the problem by only allowing constraints, that do not include more then one value of the defined variable as demonstrated, and instead excludes them from the problem definition?

    In my case the loop as been setup in order to compare the values of the array. In case the input value is set to 1 a comparison of these values is obviously not necessary anymore, even though there are still other defined decision variables that require optimization.

    Greetings...Martin

    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: OPL mathematical programming

    Posted Thu May 14, 2009 02:09 PM

    Originally posted by: SystemAdmin


    [jfk said:]

    Hello,
    well, actually reading the first sentence of yours I would have said a definite "yes!" and I could have written just no.2 below, but here we go:
    1. Have you tried to run the code you wrote? for me the following works (at the end is the result):

    int InputValue = 1;//3;
    dvar int a in 1..4;
    dvar int b in 1..5;
    int domainLowerBound[1..InputValue] = [1];//[1,2,3];
    int domainUpperBound[1..InputValue] = [8];//[8,9,10];
    dvar int A[i in 1..InputValue] in domainLowerBound[i]..domainUpperBound[i];

    maximize
      sum(i in 1..InputValue) A[i];
    subject to  {

    forall (i in 1..InputValue-1)
      forall (j in i+1..InputValue)
          a + b >= A[j];
    /*
    //with InputValue = 1
    // solution (optimal) with objective 8
    A = [8];
    a = 1;
    b = 1;

    // solution (optimal) with objective 26
    A = [8 9 9];
    a = 4;
    b = 5;
    */

    and you can see for InputValue =1 no constraint is taken into account (a and b set to some value since they are not involved in any constraint), while for InputValue=3 constraints are posted and respected. A sidecomment: in your sample code you don't have index i used just j which is fine but not very efficient if you post the same constraint many times. OK, you wanted to demonstrate something and didn't care about some details and yet... :-)

    2. if you want to make your constraints posted or not posted depending on input data the "if - then" statement is for exactly that purpose:
    ILOG OPL Development Studio 6.x > Language > Language Reference Manual > OPL, the modeling language > Constraints > Using constraints > Conditional constraints

    I hope it helps

    cheers
    #DecisionOptimization
    #MathematicalProgramming-General