Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Cplex and Java

    Posted 02/11/19 02:51 PM

    Originally posted by: A.Omidi


    Hello everybody,

     
    I try to use the Cplex Java Library for solving a linear program.
    I wrote the code in the IDE. For compile below constraint, I have some errors.
     
    *==========================
    set: {(i,k) in 1,2,3,4,5,6};
    set: {(m) in A,B,C}; 
     
    constraint (m,k):    comp(m,k) = start(m,k) + sum((i), time(m,i)*rank(i,k));
    where comp, start and rank are variables and time is given parameter.
    *===========================
     
    Would you please say that, how can I write this constraint using Cplex?
     
    Best regards

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex and Java

    Posted 02/12/19 03:06 AM

    Can you please show what you got so far and what the errors are you get?

    Also, I am not exactly clear what

    set: {(i,k) in 1,2,3,4,5,6};

    is supposed to mean. (i,k) is a pair so it cannot be an element of a set that has only numbers. Do you mean "(i,k) such that i and k are in 1..6"?

    Moreover, in

    constraint (m,k):    comp(m,k) = start(m,k) + sum((i), time(m,i)*rank(i,k));

    what is i?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex and Java

    Posted 02/12/19 07:27 AM

    Originally posted by: A.Omidi


    Dear Mr. Junglas,


    According to your comment on the problem, I have two sets.
    The first, number of works, {1,2,3,4,5,6}, and the second, number of resources, {A,B,C}.

    I define two indexes [i],[k] in the works and index [m] in the resources.

    The model has a constraint in the below form:
    *=======================
    forall(k in works, m in resources)
        comp(m,k) == start(m,k) + sum((i in works), time(m,i)*rank(i,k));
    where comp, start and rank are variables and time is given parameter.
    *=======================

     

    I was trying to write the model in the Java language using IDE.
    The form of code is such as below:
    *=======================
    for (int k = 0; k < works; k++) {
        for(int m=0; m < resource; m++){
            IloLinearNumExpr constraint = model.linearNumExpr();
            for (int i = 0; i < works; i++) {
                constraint.addTerm(1, comp[j]);
                constraint.addTerm(-1, start[j]);
                constraint.addTerm(-time[m][i], rank[i][k]);
            }
                    model.addEq(constraint, 0);
        }
    }
    *=======================

     

    When I solve the model, it does not have the correct solution.
    Please, let me know, how can I write this constraint?

    Best regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex and Java

    Posted 02/12/19 07:42 AM

    Originally posted by: Lessi


     

    I think you should export the model to see if you write it correctly.   


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex and Java

    Posted 02/12/19 11:51 AM

    Even before you export the model (which is a good idea for debugging), some things don't add up at all: In your textual description, variables comp and start are indexed by m and k. In your code however both are only indexed by j. That looks weird.

    Moreover, you are not only summing up the time*rank terms. You are also summing up comp and start! I guess you should at least move these two statements

    constraint.addTerm(1, comp[j]);
    constraint.addTerm(-1, start[j]);

    out of the inner loop.


    #CPLEXOptimizers
    #DecisionOptimization