# How I multiplicate IloBoolVar by a const?

 0 ... typedef IloArray NumVar1Matrix; typedef IloArray 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 1●1●1 accept rate: 0% fbahr ♦ 4.6k●7●16

 2 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[]. answered 21 Dec '12, 19:35 Paul Rubin ♦♦ 14.6k●5●13 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 NumVar1Matrix; typedef IloArray 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
 0 The two lines with typedef are wrong. I would replace by in the first one Similarly, I would replace by 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. answered 24 Dec '12, 06:47 jfpuget 2.5k●3●10 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 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 NumMatrix; typedef IloArray 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: '' : 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
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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