Hello,

I calculated IloExpr and have a scalar. I want it to be right side of constraint, but something wrong with format -- how could I make it work?

IloExpr FGX(env3);
for(int i=0;i<2;i++)   
    FGX += F/2 - (Gvekt[i] * valsarray[i]);
IloRangeArray IRA3(env3); 
IRA3.add(IloRange(env3,-FGX,vars3[0])); // doesn't allow to enter FGX

asked 14 Jan '14, 07:17

MariusGi's gravatar image

MariusGi
1717
accept rate: 0%

edited 14 Jan '14, 08:56

fbahr's gravatar image

fbahr ♦
4.6k716

A little more context would be helpful. What are F, Gvekt, and valsarray -- how are they initialized ...and: what kind of error is reported?

(14 Jan '14, 13:13) fbahr ♦
  • F is IloExpr,
  • Gvekt is IloExprArray (of 2 elements, each elements is IloExpr),
  • valsarray is IloNumArray (of 2 elements).

When I enter FGX

IRA3.add(IloRange(env3,FGX,vars3[0]));
//^error no instance of constructor "IloRange::IloRange" matches the argument list

More detailed code:

// **valsarray** 
cplex.getValues(vals, vars);
env.out() << "Values = " << vals << endl;
IloNumArray valsarray(env3);
valsarray.add(vals[0]);
valsarray.add(vals[1]);

// **Gvekt** 
IloExpr G(env3);
IloExprArray Gvekt(env3,2);
for(int i=0;i<2;i++){
    G=G-G;
    Gvekt[i]=G;
    for(int j=0;j<2;j++){
        G+=-(T[i][j]*duals[0][j]+T[i][j]*duals[1][j]+T[i][j]*duals[2][j])/3;
        //^ IloArray<IloNumArray> duals(env2,3), 3x2 matrix.     
    }     
}

// **F**
IloExpr F1(env3);
IloExprArray F1vekt(env3,2);
for(int i=0;i<2;i++){
   F1=F1-F1;
   F1vekt[i]=F1;
   for(int j=0;j<2;j++){
       F1+=-T[i][j]*valsarray[j]+h[0][i]/2;  
   }
}

IloExpr F11(env3);
IloExprArray F11vekt(env3,2);
for(int i=0;i<2;i++){
    F11=F11-F11;
    F11vekt[i]=F11;
    for(int j=0;j<2;j++){
        F11+=T[i][j]*duals[0][j];  
   }
}

// F2,F22,F3,F33 pretty much the same

IloExpr F(env3);
for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
        F+=(F1*F11+F2*F22+F3*F33)/3;
(15 Jan '14, 03:45) MariusGi

I don't see any particular problems with FGX, but -- if I'm not mistaken -- your code tries to create an IloRange instance using the IloRange(const IloEnv env, const IloNumExprArg expr, IloNum rhs=IloInfinity, const char * name=0) constructor. -- I. e., rhs is supposed to be an IloNum instance [e. g., vals[0]], not an IloNumVar instance [vars[0]].

link

answered 15 Jan '14, 10:53

fbahr's gravatar image

fbahr ♦
4.6k716
accept rate: 13%

I think problem with FGX, because if I change it to some constant like 0, error dissapears.

Moreover I have a constraint like this and it wors:

  IloRangeArray IRA2(env);
  for(int i=0;i<l;i++){
      IRA2.add(IloRange(env,0,T[i][0] * cplex.getValue(vars[0]) 
               + T[i][1]*cplex.getValue(vars[1])
               + W[i][0]*vars[0]+W[i][1]*vars[1]));
               //^ T and W are 2x2 matrixes (IloArray<IloNumArray>)
      con2.add(IRA2[i]);
      model2.add(IRA2[i]);
   }

EDIT: My mistake I noticed that what you said is right. Then the question is how should I change my rhs if my constraints needs to be like this:

IloRangeArray IRA3(env);
IRA3.add(IloRange(env,Gvekt[0]*vars[0]+Gvekt[1]*vars[1]+vars[2],-GFX));
IRA3.add(IloRange(env,-GFX,Gvekt[0]*vars[0]+Gvekt[1]*vars[1]));
con3.add(IRA3[0]);
con3.add(IRA3[1]);
model3.add(IRA3[0]);
model3.add(IRA3[1]);
(16 Jan '14, 03:52) MariusGi

Another interesting thing is that I tried to launch my program using correct data (just to test if it works) but It didn't work I wonder what should I change or where I did a mistake. Types an error "Concert exception caught : IloExtractable 4 IloNumVarI has not been extracted by IloAlgorithm 0044FE88"

//////---------Obj function--------------------------------------------
  model3.add(IloMinimize(env,3*vars[0]+1*vars[1]+vars[2]));
//////----------Constraint 1---------------------------------------------
  IloRangeArray IRA3(env);
  IRA3.add(IloRange(env,Gvekt[0]*vars[0]+Gvekt[1]*vars[1]+vars[2],-26));
  IRA3.add(IloRange(env,-26,Gvekt[0]*vars[0]+Gvekt[1]*vars[1]));
  con3.add(IRA3[0]);con3.add(IRA3[1]);
  model3.add(IRA3[0]);model3.add(IRA3[1]);
//////----------Constraint 2---------------------------------------------
  IloRange rr(env,5,vars[0]+vars[1]);
  con3.add(rr);
  model3.add(rr);
//////----------Solution ------------------------------------------------
      IloCplex cplex3(model3);
      if ( !cplex3.solve() ) {
         env.error() << "Failed to optimize LP." << endl;
         throw(-1);
      }
      IloNumArray vals3(env);
      cplex3.getValues(vals3, vars); 
      env.out() << "Values = " << vals3 << endl;

EDIT: Solved this problem by removing some vars which I used for other model. Now just upper problem left, still don't know what to do with contraint 1 when lhs is a IloExpr and rhs is IloNumVar and opposite.

(16 Jan '14, 04:58) MariusGi

> Then the question is how should I change my rhs if > my constraints needs to be like this:

IRA3.add(IloRange(env,Gvekt[0]*vars[0]+...,-GFX));
=> IRA3.add(IloRange(env,Gvekt[0]*vars[0]+...,cplex.getValue(-GFX)));

IRA3.add(IloRange(env,-GFX,Gvekt[0]*vars[0]+...));
=> IRA3.add(IloRange(env,cplex.getValue(-GFX),Gvekt[0]*vars[0]+...));

IloCplex inherits IloAlgorithm's getValue() method -- which takes an IloNumExprArg as argument (e. g., an IloExpr) and returns its value, if there is one, as IloNum.

(16 Jan '14, 06:01) fbahr ♦

Thanx alot ! Works great.

(16 Jan '14, 09:46) MariusGi
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×191

Asked: 14 Jan '14, 07:17

Seen: 2,137 times

Last updated: 16 Jan '14, 10:30

OR-Exchange! Your site for questions, answers, and announcements about operations research.