...
typedef IloArray<IloNumVarArray> NumVar1Matrix;
typedef IloArray<NumVarMatrix>   NumVar31Matrix;
NumVar31Matrix y(env,5);
for(i=0; i< 5; i++) {
    y[i] = NumVar1Matrix(env,ILOBOOL);
    for(j=0; j< 5; j++) {
        y[i][j] = IloNumVarArray(env,ILOBOOL);
    }
}

And I need to multiplicate the variables y[i][j] by a constant.

asked 21 Dec '12, 15:33

karineamartins's gravatar image

karineamartins
111
accept rate: 0%

edited 22 Dec '12, 13:35

fbahr's gravatar image

fbahr ♦
4.6k716


This is the CPLEX C++ API? You just multiply them by the constant in whatever expression requires it. For instance, model.add(x <= 3*y[0][0]) or model.add(x <= cap[0]*y[0][0]) where model is an instance of IloModel, x is an instance of IloNumVar and cap is double[].

link

answered 21 Dec '12, 19:35

Paul%20Rubin's gravatar image

Paul Rubin ♦♦
14.6k412
accept rate: 19%

yes, i know, but y[i][j] is a ILOBOOL.

This error appears:

error C2678: binary '*' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion)

(22 Dec '12, 09:39) karineamartins

For future reference, it's probably better to respond to an answer with a comment rather than with an "answer".

I think you'll have to show the line of code that triggers the error (along with any related declarations) in order for anyone to help.

(22 Dec '12, 10:45) Paul Rubin ♦♦

Ok i'm sorry.

I have:

...
int main()
{
  IloEnv env;
  int i=0;
  int j=0;
  try {
      IloModel model(env);
      typedef IloArray<ilonumvararray> NumVar1Matrix;
      typedef IloArray<numvarmatrix>   NumVar31Matrix;
      NumVar31Matrix y(env,5);
      for(i=0; i< 5; i++) {
          y[i] = NumVar1Matrix(env,ILOBOOL);
          for(j=0; j< 5; j++) {
              y[i][j] = IloNumVarArray(env,ILOBOOL);
  }
}

model.add(IloMinimize(env, 3*y[1][2] + 6*y[1][3] + 4*y[1][4] + 3*y[2][3] + 3*y[3][4] + 3*y[2][1] + 6*y[3][1] + 4*y[4][1] + 3*y[3][2] + 3*y[4][3])); ...

(22 Dec '12, 11:00) karineamartins

The two lines with typedef are wrong.

I would replace <ilonumvararray> by <ilonumvararray> in the first one

Similarly, I would replace <numvarmatrix> by <numvar1matrix> in the second one

You cannot ignore caps in C++ (nor in many programming languages). Moreover, you forgot the 1 in the identifier for the second typdef.

link

answered 24 Dec '12, 06:47

jfpuget's gravatar image

jfpuget
2.5k310
accept rate: 8%

Ok but the error C2678: binary '*' : no operator found which takes a left-hand operand of type 'IloNumVarArray' (or there is no acceptable conversion)continues to appear

(24 Dec '12, 07:10) karineamartins
1

Your y is a 3 dimensional array, hence y[i][j] is an array that you try to multiply by a constant. Indeed, the first typdef defines an array of IloNumVarArray, i.e. an array of arrays.

The easiest way to fix your code is probably to replace the first typedef by:

typedef IloArray<ilonumvvar> NumVar1Matrix;

(25 Dec '12, 12:01) jfpuget

Yes.. thanks! :)

(27 Dec '12, 09:34) karineamartins

And for to declare de matrix of results?

I think :

    typedef IloArray <IloNum> NumMatrix;
    typedef IloArray <NumMatrix>   Num1Matrix;
    Num1Matrix xs(env);
    for(i=0; i< 5; i++) {
        xs[i] = NumMatrix(env);
        for(j=0; j< 5; j++) {
        xs[i][j] = IloNum(env);

        }
    }

But i have the error C2440: '<function-style-cast>' : cannot convert from 'IloEnv' to 'IloNum'

tks

(27 Dec '12, 11:40) karineamartins

IloNum are plain floating point numbers, they aren't constructed with an env. This code compiles fine:

Num1Matrix xs(env);
for(i=0; i< 5; i++) {
  xs[i] = NumMatrix(env);
  for(j=0; j< 5; j++) {
    xs[i][j] = 0;
  }
}
(02 Jan '13, 07:19) jfpuget
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
×30
×21

Asked: 21 Dec '12, 15:33

Seen: 3,512 times

Last updated: 02 Jan '13, 07:19

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