Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Need help about IloNumArray and IloExprArray

  • 1.  Need help about IloNumArray and IloExprArray

    Posted 07/11/10 02:49 PM

    Originally posted by: orange2005


    Hi, everyone,

    I have 4 functions about IloNumArray and IloExprArray as followings:
    1. I want to fulfill T[i]=X[i]+constant/Y[i]
    where T is an IloNumArray or IloNumVarArray, X and Y are two IloNumVarArray.
    2. T is still the IloNumArray or IloNumVarArray, I 'd like to have
    if(T[i]>T[j]) S=S+s[j]
    3. If TT is an IloExprArray
    if(TT[i]>TT[j]) S=S+s[j]
    4. the objective is min(max(TT))

    Please help me with the codes for fulfilling the functions.
    Thanks in advance!
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/11/10 03:40 PM

    Originally posted by: SystemAdmin


    > orange2005 wrote:
    >
    > I have 4 functions about IloNumArray and IloExprArray as followings:
    > 1. I want to fulfill T[i]=X[i]+constant/Y[i]
    > where T is an IloNumArray or IloNumVarArray, X and Y are two IloNumVarArray.

    If this is the only place Y occurs, redefine the model using a different variable Yinv (the reciprocal of Y), so that the constraint reads
    T[i] = X[i]+constant*Yinv[i].
    


    If Y occurs other places, you need to shop for nonlinear optimization software; CPLEX solves linear (and some quadratic) problems.

    > 2. T is still the IloNumArray or IloNumVarArray, I 'd like to have
    > if(T[i]>T[j]) S=S+s[j]

    Two possibilities here. One is that you mean this as an algebraic relation, in which case it is equivalent to s[j] = 0 (subtract S from both sides). My guess is you meant the other interpretation: increment the previous value of S by s[j]. If the latter is correct, you have a fundamental misunderstanding of optimization models. Optimization models are not procedural programs; they effectively solve for values of all decision variables simultaneously. (The solver algorithm may behave in a sequential manner, but from the user perspective it is simultaneous -- you issue the solve command, wait, and the complete solution materializes in one lump.) So there is no analogy to variable := same variable + increment because there is no sense of "before" and "after".

    > 3. If TT is an IloExprArray
    > if(TT[i]>TT[j]) S=S+s[j]

    See above.

    > 4. the objective is min(max(TT))

    This is usually achieved by minimizing a new variable Z subject to the constraints

    Z >= TT[i] for all i.
    


    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/11/10 04:05 PM

    Originally posted by: orange2005


    Hi,Paul,

    Thank you very much for your reply!

    Could you please tell me how to compare the values of two elements of IloVarNumArray T[i] and T[j]? and two elements values of IloExprArray TT[i] and TT[j]?

    I tried >. < , and Ilomax, but they don't work.

    Thanks a lot!
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/11/10 05:01 PM

    Originally posted by: SystemAdmin


    > orange2005 wrote:

    > Could you please tell me how to compare the values of two elements of IloVarNumArray T[i] and T[j]? and two elements values of IloExprArray TT[i] and TT[j]?

    This is a somewhat complicated question. If you want to enforce a weak inequality (say
    T[i] >= T[j]
    
    for example), you just add that to the model as a constraint. If you want to test whether an inequality is satisfied (and make something else in the model contingent on it), you introduce a binary variable, and you usually also need one or possibly two constants that represent valid upper and/or lower bounds on the difference. For instance, letting z be the new binary variable, a constraint like
    T[i] <= T[j] + M*z
    
    with M a sufficiently large constant says that
    either T[i] <= T[j] or z = 1 (or both).
    
    Forcing
    z = 0 if and only if T[i] <= T[j]
    
    is trickier, and in fact is usually impossible unless T is integer-valued. For continuous T, the best you can do is introduce some small positive constant epsilon and another large positive constant L, and use two constraints:
    T[i] <= T[j] + M*z
    T[i] >= T[j] + epsilon*z - L*(1 - z).
    


    With this,
    z = 1 implies "infinity" > T[i] >= T[j] + epsilon > T[j]
    
    and
    z = 0 implies "-infinity" < T[i] <= T[j]
    


    (where L and M are surrogates for infinity). Note that this precludes
    T[j] < T[i] < T[j] + epsilon.
    
    If you drop the epsilon term, you almost get the if and only if, the catch being that z = 0 and z = 1 both allow
    T[i] = T[j].
    


    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/11/10 04:21 PM

    Originally posted by: orange2005


    And I just tried to create a new IloNumVar z
    and used
    for (i=0; i< nb; i++)
    {model.add(z>=TT[i]);}
    But I got an error when I execute the .exe file, it said "The memory could not be read"

    I changed z to be an IloExpr, the same error.

    Please tell me how to fix it?

    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/11/10 05:03 PM

    Originally posted by: SystemAdmin


    > orange2005 wrote:
    > And I just tried to create a new IloNumVar z
    > and used
    > for (i=0; i< nb; i++)
    > {model.add(z>=TT[i]);}
    > But I got an error when I execute the .exe file, it said "The memory could not be read"
    >

    I see nothing wrong with the code itself (assuming this is the C++ API). The problem may be elsewhere (nb > dimension of TT, for instance, or z not properly defined).

    /Paul
    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/11/10 09:17 PM

    Originally posted by: orange2005


    Many Thanks for your help!

    I have another question, when X1,X2,X3 are IloNumVarArray, X4 is IloNumArray,
    and if the code is X1[i]=X2[i]+IloScalProd(X3,X4);
    I got the error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class IloNumExprArg' (or there is no acceptable conversion)
    Error executing cl.exe.

    What is wrong with that? And how to fix it?

    Thanks in advance.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 01:17 AM

    Originally posted by: SystemAdmin


    I don't know what API you are using. But I guess for any API, the basic rule to follow is that you should always put all the variables on the left hand side and all the data on the left side. Take C++ API for example,

    It should be:
    model.add(X1[i] - X2[i] - IloScalProd(X3,X4) == 0);
    


    And pay attention to the IloScalProd which I have never used before, I doubt it will return a single term instead of an array of term to you. I guess what you want to do might be that
    model.add(X1[i] - X2[i] - X4[i] * X3[i] == 0);
    


    Good Luck!

    Jim
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 11:37 AM

    Originally posted by: orange2005


    Thanks Jim, it works well.

    But I really need the incremental function.

    I have some packets to transmit and a buffer to save the out-of-order packets, so if the delivery time of packet j is larger than that of packet i, then packet j will be kept in the buffer, then I have a buffer size constraint model.add(buffer_size<=buffer_constraint)
    So, I really need buffer_size=buffer_size+packet_size[j]

    What should I do with it? Use other software instead of Cplex?
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 12:29 PM

    Originally posted by: SystemAdmin


    I think you can do it this way:
    IloExpr BufferSize;
        for (int j = 0; j < J; j ++){
      BufferSize += packet_size[j];
      model.add( BufferSize <= BufferConstraint );
      BufferSize.end();
    }
    


    It is just a general idea, but you do need the "+=" operator. I recommend you to take a look at the source codes of some typical examples in the directory: ../ILOG/Cplex_yourversion/Examples/src/ ...That would be very helpful to you.

    Good Luck!
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 01:34 PM

    Originally posted by: orange2005


    Hi, Jim, first thank you for your reply.
    Actually, I need

    IloExpr BufferSize;
    for (int i=0; i< J; i++){
    for (int j = i+1; j < J; j++){
    BufferSize += packet_size[j]*(time[i]>time[j]);
    model.add( BufferSize <= BufferConstraint );
    BufferSize.end();
    }
    }
    Here time is IloNumVarArray.
    but it doesn't work, according to Paul's previous reply, this doesn't make sense.
    But I really need this function in my program.

    Do you have any idea? Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 03:34 PM

    Originally posted by: SystemAdmin


    > orange2005 wrote:

    > BufferSize.end();

    This will remove BufferSize from the constraint you just added. You don't want that.

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 04:57 PM

    Originally posted by: orange2005


    Hi, Paul,

    Sorry, I made a mistake, I need

    for (int i=0; i< J; i++){
    IloExpr BufferSize;
    for (int j = i+1; j < J; j++){
    BufferSize += packet_size[j]*(time[i]>time[j]);
    model.add( BufferSize <= BufferConstraint );
    BufferSize.end();
    }
    }

    However, I got error when execute it, I think the reason is
    BufferSize += packet_size[j]*(time[i]>time[j]);

    Can you help me?
    Thanks!
    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 06:02 PM

    Originally posted by: SystemAdmin


    Please see my previous message regarding the end method.

    If timehttp://] is a variable array, then the formulation is flawed. If time[ is a constant array, I don't see a problem.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 06:38 PM

    Originally posted by: orange2005


    Thank you Paul!

    The time is indeed a variable array.

    So you mean I can't realize the function "if the delivery time of packet j is larger than that of packet i, then packet j will be kept in the buffer by increasing the buffer size" by Cplex?

    Many Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 16.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 06:52 PM

    Originally posted by: SystemAdmin


    > orange2005 wrote:
    >
    > The time is indeed a variable array.
    >
    > So you mean I can't realize the function "if the delivery time of packet j is larger than that of packet i, then packet j will be kept in the buffer by increasing the buffer size" by Cplex?

    You cannot enforce, or condition on, a strict inequality like time[j] > time[i]. You will need to introduce a binary variable (let's call it z[j][i]) to indicate whether time[j] exceeds time[i], and you have two choices. One is to set things up so that

    time[j] > time[i] => z[j][i] = 1
    time[j] < time[i] => z[j][i] = 0
    time[j] == time[i] => z[j][i] = 0 or 1
    


    and the other is to introduce a small constant epsilon > 0 and enforce

    time[j] > time[i] + epsilon => z[j][i] = 1
    time[j] <= time[i] => z[j][i] = 0
    time[i] < time[j] < time[i] + epsilon is prohibited.
    


    The first approach leaves z ambiguous if time[i] = time[j]; the second eliminates from the feasible region solutions where time[j] is just very slightly larger than time[i].

    Besides introducing the binary variable array z, you also need to introduce constraints to connect z to the conditions listed above. Then you can multiple z[j][i] by a parameter (but not a variable!) where you were trying to use (time[j] > time[i]) to introduce a 1 or 0 value.

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 17.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/14/10 08:56 PM

    Originally posted by: orange2005


    Hi, Paul,

    Thanks a lot for your help! I followed your method, and it works well. Sorry for the late reply, I was out of town these two days.

    But I have another problem that I set a bool variable matrix x[i][j] (it is another binary variable instead of z[i][j]), most results I got are 1 and 0, but I also got 0.999995 and 5e-006, since I need to check whether x[i][j]==1 && x[i][k]==1, so even that small errors generate great influence, could you please tell me how to get exact 1 and 0?

    And I'd like to know what are the largest float number and positive smallest float number in Cplex?

    Thank you very much!
    #CPLEXOptimizers
    #DecisionOptimization


  • 18.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/14/10 10:53 PM

    Originally posted by: orange2005


    And Itried to change the x matrix to be integer variable matrix, but I still got the same results

    And if I use IloRound, I got
    error C2664: 'IloRound' : cannot convert parameter 1 from 'class IloNumExprArg' to 'double'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    I think it's because I need to check x[i][j]==1 && x[i][k]==1 by IloIfThen.

    What should I do?
    #CPLEXOptimizers
    #DecisionOptimization


  • 19.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/15/10 10:56 AM

    Originally posted by: SystemAdmin


    Change your tests. Rounding error is a fact of life. If x[i][j] is boolean, then logically x[i][j] == 1 is the equivalent to x[i][j] > 0.5; but the latter is not susceptible to rounding error.

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 20.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/15/10 11:06 AM

    Originally posted by: orange2005


    Thanks! It is a smart idea!
    #CPLEXOptimizers
    #DecisionOptimization


  • 21.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/15/10 04:40 PM

    Originally posted by: orange2005


    Hi, Paul,

    I just tried that method, I used
    x[i][j]>0.5 && x[i][k]>0.5
    But I got the error error C2666: '>' : 2 overloads have similar conversions
    Error executing cl.exe.

    I tried for x is bool variable matrix and for x is integer variable matrix.

    But if I used x[i][j]>=0.5 && x[i][k]>=0.5
    The Buliding is suceesful, however, I cannot get the results I expected, it seems that this comparison is been ignored.

    Could you help me out?
    #CPLEXOptimizers
    #DecisionOptimization


  • 22.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/15/10 04:43 PM

    Originally posted by: orange2005


    So the current "best" case is still use

    IloAbs(x[i][j])==1 && IloAbs(x[i][k])==1

    for x is bool variable matrix

    But it works only good for both x[i][j] and x[j][k] equal 1 or 0, if the round error occures, it failed.
    #CPLEXOptimizers
    #DecisionOptimization


  • 23.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/15/10 05:49 PM

    Originally posted by: SystemAdmin


    Is x an IloVar or a double? You want to apply the test to the value of x, not to the variable itself.

    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 24.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/15/10 06:01 PM

    Originally posted by: orange2005


    Hi, Paul,

    The x is BoolVarMatrix with n dimensions, and for each dimension, x[i] is a IloBoolVarArray with dimension n. (I also tried integer matrix IntVarMatrix and IloIntVarArray, the same results)

    Some codes are used to assign x[i][j] to be 0 or 1 with one constraint, sum(x[i][j])=1 for every i.

    Then I need to check the value of x[i][k] and x[j][k], if x[i][k]==x[j][k]==1, I will ensure one constraint on another variable, so I will use model.add(IloIfThen(env, (IloAbs(x[i][k])==1 && IloAbs(x[j][k])==1), here is one constraint, say C1));

    It seems that the code works for x[i][k] and x[j][k] equal to 0 and 1, since the results obey the constraint C1.

    But I got some round error results, so the code failed for these cases.

    Thank you!
    #CPLEXOptimizers
    #DecisionOptimization


  • 25.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/19/10 05:34 AM

    Originally posted by: SystemAdmin


    Try this:
    cplex.getValue(x[i][j])>0.5 && cplex.getValue(x[i][k]>0.5)
    

    As Paul said, you must apply the test to the actual value of the variables and not to the variables themselves.
    Your code
    x[i][j] > 0.5
    

    silently generates a new constraint (thanks to C++ operator overloading). It does not do what you want.
    #CPLEXOptimizers
    #DecisionOptimization


  • 26.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/24/10 06:49 PM

    Originally posted by: orange2005


    Hi, Daniel,

    Thanks a lot for your help!

    I am sorry for the late reply, since I could not use the computer with Cplex these days, it was locked by my labmates.

    I tried cplex.getValue(x[i][k])>0.5 && cplex.getValue(x[j][k])>0.5

    but got the error
    error C2665: 'IloIfThen::IloIfThen' : none of the 4 overloads can convert parameter 2 from type 'bool'
    Error executing cl.exe.

    I also tried (cplex.getValue(x[i][k]>0.5) && cplex.getValue(x[j][k]>0.5))

    and got the following error
    error C2666: '>' : 2 overloads have similar conversions

    What should I do? Thanks in advance.
    #CPLEXOptimizers
    #DecisionOptimization


  • 27.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/25/10 11:47 AM

    Originally posted by: orange2005


    Actually I want

    if (x[i][k]==1 && x[j][k]==1)
    model.add(T0[i] >= T0[j]+(size[j]/b_p[k]) || T0[j] >=T0[i]+(size[i]/b_p[k]));

    it means that two packets i and j, if they transmit on the same path, their transmission time won't overlap.

    x is bool variable matrix, and T0 is floating point variable, while size and b_p are constant array

    Now I use IloIfThen to check the x values, and cplex.setParam(IloCplex::EpInt,0) to force the bool values to be 1 or 0.

    But the results are wrong sometimes, while they are correct sometimes.

    I also tried model.add (T0[i] >= (T0[j]+(size[j]/b_p[k]))*x[i][k]*x[j][k] || T0[j] >=(T0[i]+(size[i]/b_p[k])*x[i][k]*x[j][k]));

    But I got Error when I tried to execute the program.

    Please help me. Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 28.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/25/10 07:13 PM

    Originally posted by: orange2005


    I have figured ou the solution to my previous problem, but the new solution is not perfect.

    I am using
    model.add( (T0[i]-T0[j]-size[j]/b_p[k]+M*(1-x[i][k])+M*(1-x[j][k])>=0) || (T0[j]-T0[i]-size[i]/b_p[k]+M*(1-x[i][k])+M*(1-x[j][k])>=0) );

    where M is a large integer number, so when x[i][k]=x[j][k]=1, it equals to my expected constraint, when any of them equals to 0, it is T0[i]>= -infinity.

    However, it does not work sometimes, in one of my tests, the output for packet 1 has start time 5.5 end time 9.5 but the packet 7 has output start time 9, so there is an overlap for the two transmissions.

    Then, I changed the code to
    model.add (xx[k][i]j-i-1-IloMin(x[i][k],x[j][k])==0);
    model.add( (T0[i]-T0[j]-size[j]/b_p[k]-epsilon1*xx[k][i]j-1-i+M*(1-x[i][k])+M*(1-x[j][k])>=0) || (T0[j]-T0[i]-size[i]/b_p[k]-epsilon1*xx[k][i]j-1-i+M*(1-x[i][k])+M*(1-x[j][k])>=0) );

    where epsilon1=0.0001
    The resluts are correct after this change.
    However, I cannot make epsilon to be less, say 0.00001, or it will be an overlap again.

    Anyone know how to avoid this?
    Thanks a lot!
    #CPLEXOptimizers
    #DecisionOptimization


  • 29.  Re: Need help about IloNumArray and IloExprArray

    Posted 08/16/10 11:09 AM

    Originally posted by: SystemAdmin


    Did you try to do something explicit like this:
    IloAnd ifClause(env);
    ifClause.add(x[i][k] == 1);
    ifClause.add(x[j][k] == 1);
     
    IloOr thenClause(env);
    thenClause.add(T0[i] >= T0[j] + (size[j] / b_p[k]));
    thenClause.add(T0[j] >=T0[i]+(size[i]/b_p[k]));
     
    model.add(IloIfThen(env, ifClause, thenClause));
    

    Hopefully CPLEX will not run into the same numeric troubles you have as it uses indicator constraints internally. Does something like the above help?
    You may also export the model for a small instance (using cplex.exportModel("ifthen.lp")) to verify that the constraints generated are in fact what you intend.
    #CPLEXOptimizers
    #DecisionOptimization


  • 30.  Re: Need help about IloNumArray and IloExprArray

    Posted 08/16/10 11:11 AM

    Originally posted by: SystemAdmin


    Of course, x[j][k] should be an instance of IloBoolVar. Otherwise this will not work as expected.
    #CPLEXOptimizers
    #DecisionOptimization


  • 31.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/21/11 01:01 PM

    Originally posted by: orange2005


    Hi,

    I have another question.

    In my model, there is an integer array A. And an integer variable array x.

    I want to use the value A[xi] in a constraint, but I got an error "binary '[' : no operator found which takes a right-hand operand of type 'IloIntVar' (or there is no acceptable conversion)"

    Then I tried A[cplex.getValue(xi]), but I got "Error 1217: No Solution Exist".

    Can anyone help me out?

    Thank you in advance.
    #CPLEXOptimizers
    #DecisionOptimization


  • 32.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/21/11 02:54 PM

    Originally posted by: SystemAdmin


    What you are trying to do is legal in constraint programming but illegal in mathematical programming.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 33.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/21/11 02:57 PM

    Originally posted by: orange2005


    Thank you, Prof. Paul.

    So, I cannot have it in C++?
    #CPLEXOptimizers
    #DecisionOptimization


  • 34.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/21/11 03:19 PM

    Originally posted by: orange2005


    I think I can use for-loop to get (A[j]*(x[i]==j))

    But is there any more efficient way to code it, instead of for-loop?
    #CPLEXOptimizers
    #DecisionOptimization


  • 35.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/21/11 05:50 PM

    Originally posted by: SystemAdmin


    I'm not sure what you man by a for-loop. If you want an algebraic expression that add Ai if x=I, one approach is to set x = x1 + 2x2 + ... + n*xn where x1, ..., cm are binary variables, and then sum A1*x1 + ... + An*cm.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 36.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/21/11 06:09 PM

    Originally posted by: orange2005


    Thanks, Paul.

    I have changed to use binary variable array x1, x2, x3,...xn, and x=a1*x1+a2*x2+...+an*xn.

    I have another binary variable array y1, y2, ... yn, and y=b1*y1+b2*y2+...+bn*yn. (a and b are given integer array.)

    I don't know how can I get B[x][y], where B is an input binary matrix (with size 31*31), I need to use the value of B[x][y](=1 or =0) in a constraint.

    Thank you.
    #CPLEXOptimizers
    #DecisionOptimization


  • 37.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/22/11 11:03 AM

    Originally posted by: SystemAdmin


    New binary variables zij, defined by

    zij <= xi
    zij <= yj
    zij >= xi + yj - 1

    then sum Bij*zij.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 38.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/22/11 11:17 AM

    Originally posted by: orange2005


    Thank you so much!!
    #CPLEXOptimizers
    #DecisionOptimization


  • 39.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/22/11 01:47 PM

    Originally posted by: orange2005


    I have another question about Variable Matrix.

    If I have a 2-dimension integer variable matrix with size m*n, and I can transfer it to a one dimensional matrix mn*1, can this transformation reduce time or memory?

    Thank you!
    #CPLEXOptimizers
    #DecisionOptimization


  • 40.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/23/11 07:33 AM

    Originally posted by: SystemAdmin


    This will not affect solution or setup time at all.
    In general it will also not affect memory usage. There are some very special cases, for example, it m is very large then using a 1-dim array may indeed save some memory. In general, I don't think that it is worth playing with that. A potential exception is when you can implement the 1-dim array as a sparse array (i.e., one that only holds the non-zero elements). This may save a lot of memory, depending on the data stored in the matrix.
    #CPLEXOptimizers
    #DecisionOptimization


  • 41.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/23/11 02:28 PM

    Originally posted by: orange2005


    Thanks a lot for your reply.

    BTW, about IloSum, how can I sum over an array for an index range i to j, i.e., x[i]+xi+1+x[j]?

    Thank you.
    #CPLEXOptimizers
    #DecisionOptimization


  • 42.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/24/11 03:45 AM

    Originally posted by: SystemAdmin


    I don't see a direct way to do this. What comes to mind are the following two loops:
    IloExpr sum(x.getEnv());
    for (IloInt k = i; k <= j; ++k)
       sum += x[k];
    // or
    IloNumVarArray tmp(x.getEnv(), 1 + j - i);
    for (IloInt k = i; k < = j; ++k)
       tmp[k - i] = x[k];
    ... = IloSum(tmp);
    tmp.end();
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 43.  Re: Need help about IloNumArray and IloExprArray

    Posted 11/24/11 04:58 PM

    Originally posted by: orange2005


    Thanks a lot!
    #CPLEXOptimizers
    #DecisionOptimization


  • 44.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/16/10 12:47 PM

    Originally posted by: orange2005


    I also tried to set the SEpInt parameter to 0

    by cplex.setParam (IloCplex::EpInt,0);

    But I got the errors :
    error C2065: 'cplex' : undeclared identifier
    error C2228: left of '.setParam' must have class/struct/union type
    Error executing cl.exe.

    Is any solution to avoid the effect of rounding errors for my problem?

    Thanks in advance!
    #CPLEXOptimizers
    #DecisionOptimization


  • 45.  Re: Need help about IloNumArray and IloExprArray

    Posted 07/12/10 10:33 AM

    Originally posted by: SystemAdmin


    > orange2005 wrote:
    > I have another question, when X1,X2,X3 are IloNumVarArray, X4 is IloNumArray,
    > and if the code is X1[i]=X2[i]+IloScalProd(X3,X4);
    > I got the error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class IloNumExprArg' (or there is no acceptable conversion)

    = is an assignment operator.
    == is the "equals" relational operator.

    /Paul
    #CPLEXOptimizers
    #DecisionOptimization