Topic
2 replies Latest Post - ‏2013-04-06T21:50:01Z by SystemAdmin
SystemAdmin
SystemAdmin
7929 Posts
ACCEPTED ANSWER

Pinned topic Any way to simplify my code?

‏2013-03-31T02:31:31Z |
The following function optimize a matrix using CPLEX library.
There are many cases for the matrices, but this function considers only one case.
More specifically, it considers 2*4 by 2*4 matrices(8*8) with 5 colors, but the matrix can be 3*4, 4*4, 4*2, or anything the color can be 4, 11, 12, or anything.
So, I want to generalize the code, but my code is just too straightforward and lengthy and it is not easy to generalize it.
I generated my code using c++ with for loops, and I want to generate codes for other cases.

When you see me code below, do you see any part of my code that can be simplified?
Thank you!!

int optimize_matrix(matrix_t matr)
{
matrix_t m;
m = matr; // attempting to reassign matr to m.

IloEnv env;
try {
IloModel model(env);

IloBoolVarArray x00(env, 5);
IloBoolVarArray x01(env, 5);
IloBoolVarArray x02(env, 5);
IloBoolVarArray x03(env, 5);
IloBoolVarArray x04(env, 5);
IloBoolVarArray x05(env, 5);
IloBoolVarArray x06(env, 5);
IloBoolVarArray x07(env, 5);
IloBoolVarArray x10(env, 5);
IloBoolVarArray x11(env, 5);
IloBoolVarArray x12(env, 5);
IloBoolVarArray x13(env, 5);
IloBoolVarArray x14(env, 5);
IloBoolVarArray x15(env, 5);
IloBoolVarArray x16(env, 5);
IloBoolVarArray x17(env, 5);
IloBoolVarArray x20(env, 5);
IloBoolVarArray x21(env, 5);
IloBoolVarArray x22(env, 5);
IloBoolVarArray x23(env, 5);
IloBoolVarArray x24(env, 5);
IloBoolVarArray x25(env, 5);
IloBoolVarArray x26(env, 5);
IloBoolVarArray x27(env, 5);
IloBoolVarArray x30(env, 5);
IloBoolVarArray x31(env, 5);
IloBoolVarArray x32(env, 5);
IloBoolVarArray x33(env, 5);
IloBoolVarArray x34(env, 5);
IloBoolVarArray x35(env, 5);
IloBoolVarArray x36(env, 5);
IloBoolVarArray x37(env, 5);
IloBoolVarArray x40(env, 5);
IloBoolVarArray x41(env, 5);
IloBoolVarArray x42(env, 5);
IloBoolVarArray x43(env, 5);
IloBoolVarArray x44(env, 5);
IloBoolVarArray x45(env, 5);
IloBoolVarArray x46(env, 5);
IloBoolVarArray x47(env, 5);
IloBoolVarArray x50(env, 5);
IloBoolVarArray x51(env, 5);
IloBoolVarArray x52(env, 5);
IloBoolVarArray x53(env, 5);
IloBoolVarArray x54(env, 5);
IloBoolVarArray x55(env, 5);
IloBoolVarArray x56(env, 5);
IloBoolVarArray x57(env, 5);
IloBoolVarArray x60(env, 5);
IloBoolVarArray x61(env, 5);
IloBoolVarArray x62(env, 5);
IloBoolVarArray x63(env, 5);
IloBoolVarArray x64(env, 5);
IloBoolVarArray x65(env, 5);
IloBoolVarArray x66(env, 5);
IloBoolVarArray x67(env, 5);
IloBoolVarArray x70(env, 5);
IloBoolVarArray x71(env, 5);
IloBoolVarArray x72(env, 5);
IloBoolVarArray x73(env, 5);
IloBoolVarArray x74(env, 5);
IloBoolVarArray x75(env, 5);
IloBoolVarArray x76(env, 5);
IloBoolVarArray x77(env, 5);

IloRange rx00(env, 1, x00[0] + x00[1] + x00[2] + x00[3] + x00[4], 1);
IloRange rx01(env, 1, x01[0] + x01[1] + x01[2] + x01[3] + x01[4], 1);
IloRange rx02(env, 1, x02[0] + x02[1] + x02[2] + x02[3] + x02[4], 1);
IloRange rx03(env, 1, x03[0] + x03[1] + x03[2] + x03[3] + x03[4], 1);
IloRange rx04(env, 1, x04[0] + x04[1] + x04[2] + x04[3] + x04[4], 1);
IloRange rx05(env, 1, x05[0] + x05[1] + x05[2] + x05[3] + x05[4], 1);
IloRange rx06(env, 1, x06[0] + x06[1] + x06[2] + x06[3] + x06[4], 1);
IloRange rx07(env, 1, x07[0] + x07[1] + x07[2] + x07[3] + x07[4], 1);
IloRange rx10(env, 1, x10[0] + x10[1] + x10[2] + x10[3] + x10[4], 1);
IloRange rx11(env, 1, x11[0] + x11[1] + x11[2] + x11[3] + x11[4], 1);
IloRange rx12(env, 1, x12[0] + x12[1] + x12[2] + x12[3] + x12[4], 1);
IloRange rx13(env, 1, x13[0] + x13[1] + x13[2] + x13[3] + x13[4], 1);
IloRange rx14(env, 1, x14[0] + x14[1] + x14[2] + x14[3] + x14[4], 1);
IloRange rx15(env, 1, x15[0] + x15[1] + x15[2] + x15[3] + x15[4], 1);
IloRange rx16(env, 1, x16[0] + x16[1] + x16[2] + x16[3] + x16[4], 1);
IloRange rx17(env, 1, x17[0] + x17[1] + x17[2] + x17[3] + x17[4], 1);
IloRange rx20(env, 1, x20[0] + x20[1] + x20[2] + x20[3] + x20[4], 1);
IloRange rx21(env, 1, x21[0] + x21[1] + x21[2] + x21[3] + x21[4], 1);
IloRange rx22(env, 1, x22[0] + x22[1] + x22[2] + x22[3] + x22[4], 1);
IloRange rx23(env, 1, x23[0] + x23[1] + x23[2] + x23[3] + x23[4], 1);
IloRange rx24(env, 1, x24[0] + x24[1] + x24[2] + x24[3] + x24[4], 1);
IloRange rx25(env, 1, x25[0] + x25[1] + x25[2] + x25[3] + x25[4], 1);
IloRange rx26(env, 1, x26[0] + x26[1] + x26[2] + x26[3] + x26[4], 1);
IloRange rx27(env, 1, x27[0] + x27[1] + x27[2] + x27[3] + x27[4], 1);
IloRange rx30(env, 1, x30[0] + x30[1] + x30[2] + x30[3] + x30[4], 1);
IloRange rx31(env, 1, x31[0] + x31[1] + x31[2] + x31[3] + x31[4], 1);
IloRange rx32(env, 1, x32[0] + x32[1] + x32[2] + x32[3] + x32[4], 1);
IloRange rx33(env, 1, x33[0] + x33[1] + x33[2] + x33[3] + x33[4], 1);
IloRange rx34(env, 1, x34[0] + x34[1] + x34[2] + x34[3] + x34[4], 1);
IloRange rx35(env, 1, x35[0] + x35[1] + x35[2] + x35[3] + x35[4], 1);
IloRange rx36(env, 1, x36[0] + x36[1] + x36[2] + x36[3] + x36[4], 1);
IloRange rx37(env, 1, x37[0] + x37[1] + x37[2] + x37[3] + x37[4], 1);
IloRange rx40(env, 1, x40[0] + x40[1] + x40[2] + x40[3] + x40[4], 1);
IloRange rx41(env, 1, x41[0] + x41[1] + x41[2] + x41[3] + x41[4], 1);
IloRange rx42(env, 1, x42[0] + x42[1] + x42[2] + x42[3] + x42[4], 1);
IloRange rx43(env, 1, x43[0] + x43[1] + x43[2] + x43[3] + x43[4], 1);
IloRange rx44(env, 1, x44[0] + x44[1] + x44[2] + x44[3] + x44[4], 1);
IloRange rx45(env, 1, x45[0] + x45[1] + x45[2] + x45[3] + x45[4], 1);
IloRange rx46(env, 1, x46[0] + x46[1] + x46[2] + x46[3] + x46[4], 1);
IloRange rx47(env, 1, x47[0] + x47[1] + x47[2] + x47[3] + x47[4], 1);
IloRange rx50(env, 1, x50[0] + x50[1] + x50[2] + x50[3] + x50[4], 1);
IloRange rx51(env, 1, x51[0] + x51[1] + x51[2] + x51[3] + x51[4], 1);
IloRange rx52(env, 1, x52[0] + x52[1] + x52[2] + x52[3] + x52[4], 1);
IloRange rx53(env, 1, x53[0] + x53[1] + x53[2] + x53[3] + x53[4], 1);
IloRange rx54(env, 1, x54[0] + x54[1] + x54[2] + x54[3] + x54[4], 1);
IloRange rx55(env, 1, x55[0] + x55[1] + x55[2] + x55[3] + x55[4], 1);
IloRange rx56(env, 1, x56[0] + x56[1] + x56[2] + x56[3] + x56[4], 1);
IloRange rx57(env, 1, x57[0] + x57[1] + x57[2] + x57[3] + x57[4], 1);
IloRange rx60(env, 1, x60[0] + x60[1] + x60[2] + x60[3] + x60[4], 1);
IloRange rx61(env, 1, x61[0] + x61[1] + x61[2] + x61[3] + x61[4], 1);
IloRange rx62(env, 1, x62[0] + x62[1] + x62[2] + x62[3] + x62[4], 1);
IloRange rx63(env, 1, x63[0] + x63[1] + x63[2] + x63[3] + x63[4], 1);
IloRange rx64(env, 1, x64[0] + x64[1] + x64[2] + x64[3] + x64[4], 1);
IloRange rx65(env, 1, x65[0] + x65[1] + x65[2] + x65[3] + x65[4], 1);
IloRange rx66(env, 1, x66[0] + x66[1] + x66[2] + x66[3] + x66[4], 1);
IloRange rx67(env, 1, x67[0] + x67[1] + x67[2] + x67[3] + x67[4], 1);
IloRange rx70(env, 1, x70[0] + x70[1] + x70[2] + x70[3] + x70[4], 1);
IloRange rx71(env, 1, x71[0] + x71[1] + x71[2] + x71[3] + x71[4], 1);
IloRange rx72(env, 1, x72[0] + x72[1] + x72[2] + x72[3] + x72[4], 1);
IloRange rx73(env, 1, x73[0] + x73[1] + x73[2] + x73[3] + x73[4], 1);
IloRange rx74(env, 1, x74[0] + x74[1] + x74[2] + x74[3] + x74[4], 1);
IloRange rx75(env, 1, x75[0] + x75[1] + x75[2] + x75[3] + x75[4], 1);
IloRange rx76(env, 1, x76[0] + x76[1] + x76[2] + x76[3] + x76[4], 1);
IloRange rx77(env, 1, x77[0] + x77[1] + x77[2] + x77[3] + x77[4], 1);

IloRange rbr0mx0(env, 0, \
m[0][0]*x00[0]+m[0][1]*x01[0]+m[0][2]*x02[0]+m[0][3]*x03[0]+m[0][4]*x04[0]+m[0][5]*x05[0]+m[0][6]*x06[0]+m[0][7]*x07[0]+
m[1][0]*x10[0]+m[1][1]*x11[0]+m[1][2]*x12[0]+m[1][3]*x13[0]+m[1][4]*x14[0]+m[1][5]*x15[0]+m[1][6]*x16[0]+m[1][7]*x17[0]+
m[2][0]*x20[0]+m[2][1]*x21[0]+m[2][2]*x22[0]+m[2][3]*x23[0]+m[2][4]*x24[0]+m[2][5]*x25[0]+m[2][6]*x26[0]+m[2][7]*x27[0]+
m[3][0]*x30[0]+m[3][1]*x31[0]+m[3][2]*x32[0]+m[3][3]*x33[0]+m[3][4]*x34[0]+m[3][5]*x35[0]+m[3][6]*x36[0]+m[3][7]*x37[0] \
, 10);

IloRange rbr0mx1(env, 0, \
m[0][0]*x00[1]+m[0][1]*x01[1]+m[0][2]*x02[1]+m[0][3]*x03[1]+m[0][4]*x04[1]+m[0][5]*x05[1]+m[0][6]*x06[1]+m[0][7]*x07[1]+
m[1][0]*x10[1]+m[1][1]*x11[1]+m[1][2]*x12[1]+m[1][3]*x13[1]+m[1][4]*x14[1]+m[1][5]*x15[1]+m[1][6]*x16[1]+m[1][7]*x17[1]+
m[2][0]*x20[1]+m[2][1]*x21[1]+m[2][2]*x22[1]+m[2][3]*x23[1]+m[2][4]*x24[1]+m[2][5]*x25[1]+m[2][6]*x26[1]+m[2][7]*x27[1]+
m[3][0]*x30[1]+m[3][1]*x31[1]+m[3][2]*x32[1]+m[3][3]*x33[1]+m[3][4]*x34[1]+m[3][5]*x35[1]+m[3][6]*x36[1]+m[3][7]*x37[1] \
, 10);

IloRange rbr0mx2(env, 0, \
m[0][0]*x00[2]+m[0][1]*x01[2]+m[0][2]*x02[2]+m[0][3]*x03[2]+m[0][4]*x04[2]+m[0][5]*x05[2]+m[0][6]*x06[2]+m[0][7]*x07[2]+
m[1][0]*x10[2]+m[1][1]*x11[2]+m[1][2]*x12[2]+m[1][3]*x13[2]+m[1][4]*x14[2]+m[1][5]*x15[2]+m[1][6]*x16[2]+m[1][7]*x17[2]+
m[2][0]*x20[2]+m[2][1]*x21[2]+m[2][2]*x22[2]+m[2][3]*x23[2]+m[2][4]*x24[2]+m[2][5]*x25[2]+m[2][6]*x26[2]+m[2][7]*x27[2]+
m[3][0]*x30[2]+m[3][1]*x31[2]+m[3][2]*x32[2]+m[3][3]*x33[2]+m[3][4]*x34[2]+m[3][5]*x35[2]+m[3][6]*x36[2]+m[3][7]*x37[2] \
, 10);

IloRange rbr0mx3(env, 0, \
m[0][0]*x00[3]+m[0][1]*x01[3]+m[0][2]*x02[3]+m[0][3]*x03[3]+m[0][4]*x04[3]+m[0][5]*x05[3]+m[0][6]*x06[3]+m[0][7]*x07[3]+
m[1][0]*x10[3]+m[1][1]*x11[3]+m[1][2]*x12[3]+m[1][3]*x13[3]+m[1][4]*x14[3]+m[1][5]*x15[3]+m[1][6]*x16[3]+m[1][7]*x17[3]+
m[2][0]*x20[3]+m[2][1]*x21[3]+m[2][2]*x22[3]+m[2][3]*x23[3]+m[2][4]*x24[3]+m[2][5]*x25[3]+m[2][6]*x26[3]+m[2][7]*x27[3]+
m[3][0]*x30[3]+m[3][1]*x31[3]+m[3][2]*x32[3]+m[3][3]*x33[3]+m[3][4]*x34[3]+m[3][5]*x35[3]+m[3][6]*x36[3]+m[3][7]*x37[3] \
, 10);

IloRange rbr0mx4(env, 0, \
m[0][0]*x00[4]+m[0][1]*x01[4]+m[0][2]*x02[4]+m[0][3]*x03[4]+m[0][4]*x04[4]+m[0][5]*x05[4]+m[0][6]*x06[4]+m[0][7]*x07[4]+
m[1][0]*x10[4]+m[1][1]*x11[4]+m[1][2]*x12[4]+m[1][3]*x13[4]+m[1][4]*x14[4]+m[1][5]*x15[4]+m[1][6]*x16[4]+m[1][7]*x17[4]+
m[2][0]*x20[4]+m[2][1]*x21[4]+m[2][2]*x22[4]+m[2][3]*x23[4]+m[2][4]*x24[4]+m[2][5]*x25[4]+m[2][6]*x26[4]+m[2][7]*x27[4]+
m[3][0]*x30[4]+m[3][1]*x31[4]+m[3][2]*x32[4]+m[3][3]*x33[4]+m[3][4]*x34[4]+m[3][5]*x35[4]+m[3][6]*x36[4]+m[3][7]*x37[4] \
, 10);
IloRange rbr1mx0(env, 0, \
m[4][0]*x40[0]+m[4][1]*x41[0]+m[4][2]*x42[0]+m[4][3]*x43[0]+m[4][4]*x44[0]+m[4][5]*x45[0]+m[4][6]*x46[0]+m[4][7]*x47[0]+
m[5][0]*x50[0]+m[5][1]*x51[0]+m[5][2]*x52[0]+m[5][3]*x53[0]+m[5][4]*x54[0]+m[5][5]*x55[0]+m[5][6]*x56[0]+m[5][7]*x57[0]+
m[6][0]*x60[0]+m[6][1]*x61[0]+m[6][2]*x62[0]+m[6][3]*x63[0]+m[6][4]*x64[0]+m[6][5]*x65[0]+m[6][6]*x66[0]+m[6][7]*x67[0]+
m[7][0]*x70[0]+m[7][1]*x71[0]+m[7][2]*x72[0]+m[7][3]*x73[0]+m[7][4]*x74[0]+m[7][5]*x75[0]+m[7][6]*x76[0]+m[7][7]*x77[0] \
, 10);

IloRange rbr1mx1(env, 0, \
m[4][0]*x40[1]+m[4][1]*x41[1]+m[4][2]*x42[1]+m[4][3]*x43[1]+m[4][4]*x44[1]+m[4][5]*x45[1]+m[4][6]*x46[1]+m[4][7]*x47[1]+
m[5][0]*x50[1]+m[5][1]*x51[1]+m[5][2]*x52[1]+m[5][3]*x53[1]+m[5][4]*x54[1]+m[5][5]*x55[1]+m[5][6]*x56[1]+m[5][7]*x57[1]+
m[6][0]*x60[1]+m[6][1]*x61[1]+m[6][2]*x62[1]+m[6][3]*x63[1]+m[6][4]*x64[1]+m[6][5]*x65[1]+m[6][6]*x66[1]+m[6][7]*x67[1]+
m[7][0]*x70[1]+m[7][1]*x71[1]+m[7][2]*x72[1]+m[7][3]*x73[1]+m[7][4]*x74[1]+m[7][5]*x75[1]+m[7][6]*x76[1]+m[7][7]*x77[1] \
, 10);

IloRange rbr1mx2(env, 0, \
m[4][0]*x40[2]+m[4][1]*x41[2]+m[4][2]*x42[2]+m[4][3]*x43[2]+m[4][4]*x44[2]+m[4][5]*x45[2]+m[4][6]*x46[2]+m[4][7]*x47[2]+
m[5][0]*x50[2]+m[5][1]*x51[2]+m[5][2]*x52[2]+m[5][3]*x53[2]+m[5][4]*x54[2]+m[5][5]*x55[2]+m[5][6]*x56[2]+m[5][7]*x57[2]+
m[6][0]*x60[2]+m[6][1]*x61[2]+m[6][2]*x62[2]+m[6][3]*x63[2]+m[6][4]*x64[2]+m[6][5]*x65[2]+m[6][6]*x66[2]+m[6][7]*x67[2]+
m[7][0]*x70[2]+m[7][1]*x71[2]+m[7][2]*x72[2]+m[7][3]*x73[2]+m[7][4]*x74[2]+m[7][5]*x75[2]+m[7][6]*x76[2]+m[7][7]*x77[2] \
, 10);

IloRange rbr1mx3(env, 0, \
m[4][0]*x40[3]+m[4][1]*x41[3]+m[4][2]*x42[3]+m[4][3]*x43[3]+m[4][4]*x44[3]+m[4][5]*x45[3]+m[4][6]*x46[3]+m[4][7]*x47[3]+
m[5][0]*x50[3]+m[5][1]*x51[3]+m[5][2]*x52[3]+m[5][3]*x53[3]+m[5][4]*x54[3]+m[5][5]*x55[3]+m[5][6]*x56[3]+m[5][7]*x57[3]+
m[6][0]*x60[3]+m[6][1]*x61[3]+m[6][2]*x62[3]+m[6][3]*x63[3]+m[6][4]*x64[3]+m[6][5]*x65[3]+m[6][6]*x66[3]+m[6][7]*x67[3]+
m[7][0]*x70[3]+m[7][1]*x71[3]+m[7][2]*x72[3]+m[7][3]*x73[3]+m[7][4]*x74[3]+m[7][5]*x75[3]+m[7][6]*x76[3]+m[7][7]*x77[3] \
, 10);

IloRange rbr1mx4(env, 0, \
m[4][0]*x40[4]+m[4][1]*x41[4]+m[4][2]*x42[4]+m[4][3]*x43[4]+m[4][4]*x44[4]+m[4][5]*x45[4]+m[4][6]*x46[4]+m[4][7]*x47[4]+
m[5][0]*x50[4]+m[5][1]*x51[4]+m[5][2]*x52[4]+m[5][3]*x53[4]+m[5][4]*x54[4]+m[5][5]*x55[4]+m[5][6]*x56[4]+m[5][7]*x57[4]+
m[6][0]*x60[4]+m[6][1]*x61[4]+m[6][2]*x62[4]+m[6][3]*x63[4]+m[6][4]*x64[4]+m[6][5]*x65[4]+m[6][6]*x66[4]+m[6][7]*x67[4]+
m[7][0]*x70[4]+m[7][1]*x71[4]+m[7][2]*x72[4]+m[7][3]*x73[4]+m[7][4]*x74[4]+m[7][5]*x75[4]+m[7][6]*x76[4]+m[7][7]*x77[4] \
, 10);
IloRange rbc0mx0(env, 0, \
m[0][0]*x00[0]+m[0][1]*x01[0]+m[0][2]*x02[0]+m[0][3]*x03[0]+
m[1][0]*x10[0]+m[1][1]*x11[0]+m[1][2]*x12[0]+m[1][3]*x13[0]+
m[2][0]*x20[0]+m[2][1]*x21[0]+m[2][2]*x22[0]+m[2][3]*x23[0]+
m[3][0]*x30[0]+m[3][1]*x31[0]+m[3][2]*x32[0]+m[3][3]*x33[0]+
m[4][0]*x40[0]+m[4][1]*x41[0]+m[4][2]*x42[0]+m[4][3]*x43[0]+
m[5][0]*x50[0]+m[5][1]*x51[0]+m[5][2]*x52[0]+m[5][3]*x53[0]+
m[6][0]*x60[0]+m[6][1]*x61[0]+m[6][2]*x62[0]+m[6][3]*x63[0]+
m[7][0]*x70[0]+m[7][1]*x71[0]+m[7][2]*x72[0]+m[7][3]*x73[0], 10);

IloRange rbc0mx1(env, 0, \
m[0][0]*x00[1]+m[0][1]*x01[1]+m[0][2]*x02[1]+m[0][3]*x03[1]+
m[1][0]*x10[1]+m[1][1]*x11[1]+m[1][2]*x12[1]+m[1][3]*x13[1]+
m[2][0]*x20[1]+m[2][1]*x21[1]+m[2][2]*x22[1]+m[2][3]*x23[1]+
m[3][0]*x30[1]+m[3][1]*x31[1]+m[3][2]*x32[1]+m[3][3]*x33[1]+
m[4][0]*x40[1]+m[4][1]*x41[1]+m[4][2]*x42[1]+m[4][3]*x43[1]+
m[5][0]*x50[1]+m[5][1]*x51[1]+m[5][2]*x52[1]+m[5][3]*x53[1]+
m[6][0]*x60[1]+m[6][1]*x61[1]+m[6][2]*x62[1]+m[6][3]*x63[1]+
m[7][0]*x70[1]+m[7][1]*x71[1]+m[7][2]*x72[1]+m[7][3]*x73[1], 10);

IloRange rbc0mx2(env, 0, \
m[0][0]*x00[2]+m[0][1]*x01[2]+m[0][2]*x02[2]+m[0][3]*x03[2]+
m[1][0]*x10[2]+m[1][1]*x11[2]+m[1][2]*x12[2]+m[1][3]*x13[2]+
m[2][0]*x20[2]+m[2][1]*x21[2]+m[2][2]*x22[2]+m[2][3]*x23[2]+
m[3][0]*x30[2]+m[3][1]*x31[2]+m[3][2]*x32[2]+m[3][3]*x33[2]+
m[4][0]*x40[2]+m[4][1]*x41[2]+m[4][2]*x42[2]+m[4][3]*x43[2]+
m[5][0]*x50[2]+m[5][1]*x51[2]+m[5][2]*x52[2]+m[5][3]*x53[2]+
m[6][0]*x60[2]+m[6][1]*x61[2]+m[6][2]*x62[2]+m[6][3]*x63[2]+
m[7][0]*x70[2]+m[7][1]*x71[2]+m[7][2]*x72[2]+m[7][3]*x73[2], 10);

IloRange rbc0mx3(env, 0, \
m[0][0]*x00[3]+m[0][1]*x01[3]+m[0][2]*x02[3]+m[0][3]*x03[3]+
m[1][0]*x10[3]+m[1][1]*x11[3]+m[1][2]*x12[3]+m[1][3]*x13[3]+
m[2][0]*x20[3]+m[2][1]*x21[3]+m[2][2]*x22[3]+m[2][3]*x23[3]+
m[3][0]*x30[3]+m[3][1]*x31[3]+m[3][2]*x32[3]+m[3][3]*x33[3]+
m[4][0]*x40[3]+m[4][1]*x41[3]+m[4][2]*x42[3]+m[4][3]*x43[3]+
m[5][0]*x50[3]+m[5][1]*x51[3]+m[5][2]*x52[3]+m[5][3]*x53[3]+
m[6][0]*x60[3]+m[6][1]*x61[3]+m[6][2]*x62[3]+m[6][3]*x63[3]+
m[7][0]*x70[3]+m[7][1]*x71[3]+m[7][2]*x72[3]+m[7][3]*x73[3], 10);

IloRange rbc0mx4(env, 0, \
m[0][0]*x00[4]+m[0][1]*x01[4]+m[0][2]*x02[4]+m[0][3]*x03[4]+
m[1][0]*x10[4]+m[1][1]*x11[4]+m[1][2]*x12[4]+m[1][3]*x13[4]+
m[2][0]*x20[4]+m[2][1]*x21[4]+m[2][2]*x22[4]+m[2][3]*x23[4]+
m[3][0]*x30[4]+m[3][1]*x31[4]+m[3][2]*x32[4]+m[3][3]*x33[4]+
m[4][0]*x40[4]+m[4][1]*x41[4]+m[4][2]*x42[4]+m[4][3]*x43[4]+
m[5][0]*x50[4]+m[5][1]*x51[4]+m[5][2]*x52[4]+m[5][3]*x53[4]+
m[6][0]*x60[4]+m[6][1]*x61[4]+m[6][2]*x62[4]+m[6][3]*x63[4]+
m[7][0]*x70[4]+m[7][1]*x71[4]+m[7][2]*x72[4]+m[7][3]*x73[4], 10);
IloRange rbc1mx0(env, 0, \
m[0][4]*x04[0]+m[0][5]*x05[0]+m[0][6]*x06[0]+m[0][7]*x07[0]+
m[1][4]*x14[0]+m[1][5]*x15[0]+m[1][6]*x16[0]+m[1][7]*x17[0]+
m[2][4]*x24[0]+m[2][5]*x25[0]+m[2][6]*x26[0]+m[2][7]*x27[0]+
m[3][4]*x34[0]+m[3][5]*x35[0]+m[3][6]*x36[0]+m[3][7]*x37[0]+
m[4][4]*x44[0]+m[4][5]*x45[0]+m[4][6]*x46[0]+m[4][7]*x47[0]+
m[5][4]*x54[0]+m[5][5]*x55[0]+m[5][6]*x56[0]+m[5][7]*x57[0]+
m[6][4]*x64[0]+m[6][5]*x65[0]+m[6][6]*x66[0]+m[6][7]*x67[0]+
m[7][4]*x74[0]+m[7][5]*x75[0]+m[7][6]*x76[0]+m[7][7]*x77[0], 10);

IloRange rbc1mx1(env, 0, \
m[0][4]*x04[1]+m[0][5]*x05[1]+m[0][6]*x06[1]+m[0][7]*x07[1]+
m[1][4]*x14[1]+m[1][5]*x15[1]+m[1][6]*x16[1]+m[1][7]*x17[1]+
m[2][4]*x24[1]+m[2][5]*x25[1]+m[2][6]*x26[1]+m[2][7]*x27[1]+
m[3][4]*x34[1]+m[3][5]*x35[1]+m[3][6]*x36[1]+m[3][7]*x37[1]+
m[4][4]*x44[1]+m[4][5]*x45[1]+m[4][6]*x46[1]+m[4][7]*x47[1]+
m[5][4]*x54[1]+m[5][5]*x55[1]+m[5][6]*x56[1]+m[5][7]*x57[1]+
m[6][4]*x64[1]+m[6][5]*x65[1]+m[6][6]*x66[1]+m[6][7]*x67[1]+
m[7][4]*x74[1]+m[7][5]*x75[1]+m[7][6]*x76[1]+m[7][7]*x77[1], 10);

IloRange rbc1mx2(env, 0, \
m[0][4]*x04[2]+m[0][5]*x05[2]+m[0][6]*x06[2]+m[0][7]*x07[2]+
m[1][4]*x14[2]+m[1][5]*x15[2]+m[1][6]*x16[2]+m[1][7]*x17[2]+
m[2][4]*x24[2]+m[2][5]*x25[2]+m[2][6]*x26[2]+m[2][7]*x27[2]+
m[3][4]*x34[2]+m[3][5]*x35[2]+m[3][6]*x36[2]+m[3][7]*x37[2]+
m[4][4]*x44[2]+m[4][5]*x45[2]+m[4][6]*x46[2]+m[4][7]*x47[2]+
m[5][4]*x54[2]+m[5][5]*x55[2]+m[5][6]*x56[2]+m[5][7]*x57[2]+
m[6][4]*x64[2]+m[6][5]*x65[2]+m[6][6]*x66[2]+m[6][7]*x67[2]+
m[7][4]*x74[2]+m[7][5]*x75[2]+m[7][6]*x76[2]+m[7][7]*x77[2], 10);

IloRange rbc1mx3(env, 0, \
m[0][4]*x04[3]+m[0][5]*x05[3]+m[0][6]*x06[3]+m[0][7]*x07[3]+
m[1][4]*x14[3]+m[1][5]*x15[3]+m[1][6]*x16[3]+m[1][7]*x17[3]+
m[2][4]*x24[3]+m[2][5]*x25[3]+m[2][6]*x26[3]+m[2][7]*x27[3]+
m[3][4]*x34[3]+m[3][5]*x35[3]+m[3][6]*x36[3]+m[3][7]*x37[3]+
m[4][4]*x44[3]+m[4][5]*x45[3]+m[4][6]*x46[3]+m[4][7]*x47[3]+
m[5][4]*x54[3]+m[5][5]*x55[3]+m[5][6]*x56[3]+m[5][7]*x57[3]+
m[6][4]*x64[3]+m[6][5]*x65[3]+m[6][6]*x66[3]+m[6][7]*x67[3]+
m[7][4]*x74[3]+m[7][5]*x75[3]+m[7][6]*x76[3]+m[7][7]*x77[3], 10);

IloRange rbc1mx4(env, 0, \
m[0][4]*x04[4]+m[0][5]*x05[4]+m[0][6]*x06[4]+m[0][7]*x07[4]+
m[1][4]*x14[4]+m[1][5]*x15[4]+m[1][6]*x16[4]+m[1][7]*x17[4]+
m[2][4]*x24[4]+m[2][5]*x25[4]+m[2][6]*x26[4]+m[2][7]*x27[4]+
m[3][4]*x34[4]+m[3][5]*x35[4]+m[3][6]*x36[4]+m[3][7]*x37[4]+
m[4][4]*x44[4]+m[4][5]*x45[4]+m[4][6]*x46[4]+m[4][7]*x47[4]+
m[5][4]*x54[4]+m[5][5]*x55[4]+m[5][6]*x56[4]+m[5][7]*x57[4]+
m[6][4]*x64[4]+m[6][5]*x65[4]+m[6][6]*x66[4]+m[6][7]*x67[4]+
m[7][4]*x74[4]+m[7][5]*x75[4]+m[7][6]*x76[4]+m[7][7]*x77[4], 10);

model.add(rx00); //all the variables this range uses are also added automatically
model.add(rx01);
model.add(rx02);
model.add(rx03);
model.add(rx04);
model.add(rx05);
model.add(rx06);
model.add(rx07);
model.add(rx10);
model.add(rx11);
model.add(rx12);
model.add(rx13);
model.add(rx14);
model.add(rx15);
model.add(rx16);
model.add(rx17);
model.add(rx20);
model.add(rx21);
model.add(rx22);
model.add(rx23);
model.add(rx24);
model.add(rx25);
model.add(rx26);
model.add(rx27);
model.add(rx30);
model.add(rx31);
model.add(rx32);
model.add(rx33);
model.add(rx34);
model.add(rx35);
model.add(rx36);
model.add(rx37);
model.add(rx40);
model.add(rx41);
model.add(rx42);
model.add(rx43);
model.add(rx44);
model.add(rx45);
model.add(rx46);
model.add(rx47);
model.add(rx50);
model.add(rx51);
model.add(rx52);
model.add(rx53);
model.add(rx54);
model.add(rx55);
model.add(rx56);
model.add(rx57);
model.add(rx60);
model.add(rx61);
model.add(rx62);
model.add(rx63);
model.add(rx64);
model.add(rx65);
model.add(rx66);
model.add(rx67);
model.add(rx70);
model.add(rx71);
model.add(rx72);
model.add(rx73);
model.add(rx74);
model.add(rx75);
model.add(rx76);
model.add(rx77);

model.add(rbr0mx0);
model.add(rbr0mx1);
model.add(rbr0mx2);
model.add(rbr0mx3);
model.add(rbr0mx4);
model.add(rbr1mx0);
model.add(rbr1mx1);
model.add(rbr1mx2);
model.add(rbr1mx3);
model.add(rbr1mx4);

model.add(rbc0mx0);
model.add(rbc0mx1);
model.add(rbc0mx2);
model.add(rbc0mx3);
model.add(rbc0mx4);
model.add(rbc1mx0);
model.add(rbc1mx1);
model.add(rbc1mx2);
model.add(rbc1mx3);
model.add(rbc1mx4);

IloCplex cplex(env);
cplex.extract(model);
cplex.solve();
cplex.out() << "solution status = " << cplex.getStatus() << endl;
cplex.out() << endl;
/*
for (int i = 0; i < 5; i++) {
cplex.out() << " x00 = " << cplex.getValue(x00[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x01 = " << cplex.getValue(x01[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x02 = " << cplex.getValue(x02[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x03 = " << cplex.getValue(x03[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x04 = " << cplex.getValue(x04[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x05 = " << cplex.getValue(x05[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x06 = " << cplex.getValue(x06[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x07 = " << cplex.getValue(x07[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x10 = " << cplex.getValue(x10[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x11 = " << cplex.getValue(x11[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x12 = " << cplex.getValue(x12[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x13 = " << cplex.getValue(x13[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x14 = " << cplex.getValue(x14[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x15 = " << cplex.getValue(x15[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x16 = " << cplex.getValue(x16[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x17 = " << cplex.getValue(x17[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x20 = " << cplex.getValue(x20[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x21 = " << cplex.getValue(x21[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x22 = " << cplex.getValue(x22[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x23 = " << cplex.getValue(x23[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x24 = " << cplex.getValue(x24[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x25 = " << cplex.getValue(x25[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x26 = " << cplex.getValue(x26[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x27 = " << cplex.getValue(x27[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x30 = " << cplex.getValue(x30[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x31 = " << cplex.getValue(x31[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x32 = " << cplex.getValue(x32[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x33 = " << cplex.getValue(x33[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x34 = " << cplex.getValue(x34[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x35 = " << cplex.getValue(x35[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x36 = " << cplex.getValue(x36[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x37 = " << cplex.getValue(x37[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x40 = " << cplex.getValue(x40[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x41 = " << cplex.getValue(x41[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x42 = " << cplex.getValue(x42[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x43 = " << cplex.getValue(x43[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x44 = " << cplex.getValue(x44[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x45 = " << cplex.getValue(x45[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x46 = " << cplex.getValue(x46[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x47 = " << cplex.getValue(x47[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x50 = " << cplex.getValue(x50[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x51 = " << cplex.getValue(x51[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x52 = " << cplex.getValue(x52[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x53 = " << cplex.getValue(x53[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x54 = " << cplex.getValue(x54[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x55 = " << cplex.getValue(x55[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x56 = " << cplex.getValue(x56[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x57 = " << cplex.getValue(x57[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x60 = " << cplex.getValue(x60[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x61 = " << cplex.getValue(x61[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x62 = " << cplex.getValue(x62[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x63 = " << cplex.getValue(x63[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x64 = " << cplex.getValue(x64[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x65 = " << cplex.getValue(x65[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x66 = " << cplex.getValue(x66[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x67 = " << cplex.getValue(x67[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x70 = " << cplex.getValue(x70[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x71 = " << cplex.getValue(x71[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x72 = " << cplex.getValue(x72[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x73 = " << cplex.getValue(x73[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x74 = " << cplex.getValue(x74[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x75 = " << cplex.getValue(x75[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x76 = " << cplex.getValue(x76[i]) << " ";
}
cplex.out() << endl;
for (int i = 0; i < 5; i++) {
cplex.out() << " x77 = " << cplex.getValue(x77[i]) << " ";
}
cplex.out() << endl;
*/

if (cplex.getStatus() == IloAlgorithm::Infeasible){
// cplex.out() << endl << "*** the model is not infeasible ***" << endl;

ofstream outdata;
outdata.open("badmatrix.csv");
if (!outdata){cerr << "Error: file could not be opened" << endl;
exit(1);}
else{
size_t it1;
size_t it2;
size_t n = m.size();
for (it1=0;it1<n;it1++){
for (it2 = 0; it2<n; it2++){
outdata << matrit1it2 << endl;}}
}
outdata.close();
env.end();
cplex.out() << "Infeasible matrix detected" << endl;
return 6;
}
}
catch(IloException& e) {
cerr << " ERROR: " << e << endl;
}
catch(...) {
cerr << " ERROR: " << endl;
}
env.end();
return 5;
}
Updated on 2013-04-06T21:50:01Z at 2013-04-06T21:50:01Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7929 Posts
    ACCEPTED ANSWER

    Re: Any way to simplify my code?

    ‏2013-04-02T20:27:52Z  in response to SystemAdmin
    Using IloArray, you can create higher dimensional arrays. So, for instance, you can make x a 3-D array, with x15[3] becoming x[1][5][3]. Then you can build your ranges, etc. using loops.

    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)
    • SystemAdmin
      SystemAdmin
      7929 Posts
      ACCEPTED ANSWER

      Re: Any way to simplify my code?

      ‏2013-04-06T21:50:01Z  in response to SystemAdmin
      Thank you very much Dr. Rubin.
      I tried to do what you suggested as below.
      However, I am getting a couple of errors.

      What is the problem?
      Especially I cannot figure out initialization and declaration problems. For adding to the model I guess I need to use for loops again.
      Please give me some advice.
      Thank you!

      g.cpp: In function ‘int optimize_matrix(matrix_t)’:
      g.cpp:120:78: error: variable-sized object ‘range_weightedSumBR’ may not be initialized
      g.cpp:122:68: error: ‘weightedSum_BR’ was not declared in this scope
      g.cpp:122:97: error: variable-sized object ‘range_weightedSum_BR’ may not be initialized
      g.cpp:144:9: error: ‘range_weightedSum_BC’ was not declared in this scope
      g.cpp:146:59: error: ‘weightedSum_BC’ was not declared in this scope
      g.cpp:150:19: error: ‘range_SumOfColors’ was not declared in this scope
      g.cpp:151:38: error: no matching function for call to ‘IloModel::add(IloArray<IloArray<IloRange> >&)’
      g.cpp:151:38: note: candidates are:
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:64:17: note: IloExtractable IloModel::add(IloExtractable) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:64:17: note: no known conversion for argument 1 from ‘IloArray<IloArray<IloRange> >’ to ‘IloExtractable’
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:66:29: note: const IloExtractableArray& IloModel::add(const IloExtractableArray&) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:66:29: note: no known conversion for argument 1 from ‘IloArray<IloArray<IloRange> >’ to ‘const IloExtractableArray&’
      g.cpp:152:38: error: no matching function for call to ‘IloModel::add(IloArray<IloArray<IloRange> >&)’
      g.cpp:152:38: note: candidates are:
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:64:17: note: IloExtractable IloModel::add(IloExtractable) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:64:17: note: no known conversion for argument 1 from ‘IloArray<IloArray<IloRange> >’ to ‘IloExtractable’
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:66:29: note: const IloExtractableArray& IloModel::add(const IloExtractableArray&) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/concert/include/ilconcert/ilomodel.h:66:29: note: no known conversion for argument 1 from ‘IloArray<IloArray<IloRange> >’ to ‘const IloExtractableArray&’
      g.cpp:161:45: error: no matching function for call to ‘IloCplex::getValues(IloArray<IloArray<IloBoolVarArray> >&)’
      g.cpp:161:45: note: candidates are:
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:387:8: note: void IloCplex::getValues(IloNumArray, IloNumVarArray) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:387:8: note: candidate expects 2 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:391:8: note: void IloCplex::getValues(IloNumVarArray, IloNumArray) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:391:8: note: candidate expects 2 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:395:8: note: void IloCplex::getValues(IloNumArray, IloIntVarArray) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:395:8: note: candidate expects 2 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:399:8: note: void IloCplex::getValues(IloIntVarArray, IloNumArray) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplexi.h:399:8: note: candidate expects 2 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:275:1: note: void IloCplex::getValues(IloNumArray, IloNumVarArray, IloInt) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:275:1: note: candidate expects 3 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:284:1: note: void IloCplex::getValues(IloNumVarArray, IloNumArray, IloInt) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:284:1: note: candidate expects 3 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:293:1: note: void IloCplex::getValues(IloNumArray, IloIntVarArray, IloInt) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:293:1: note: candidate expects 3 arguments, 1 provided
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:302:1: note: void IloCplex::getValues(IloIntVarArray, IloNumArray, IloInt) const
      /opt/ibm/ILOG/CPLEX_Studio_Preview125/cplex/include/ilcplex/ilocplex.h:302:1: note: candidate expects 3 arguments, 1 provided
      int optimize_matrix(matrix_t matr)
      {
      matrix_t m;
      m = matr;

      m[8][8];
      m[0][0] = 6; m[1][1] = 6; m[2][2] = 6; m[3][3] = 6;
      m[0][4] = 4; m[1][4] = 4; m[2][5] = 4; m[3][5] = 4;
      m[4][7] = 10; m[5][6] = 10;
      IloEnv env;

      try {
      IloModel model(env);
      int n = 4;
      int r = 2;
      int color = 5;
      int N = n*r;
      IloArray<IloArray<IloBoolVarArray> > x(env, N); //change to IntVarArray 0~1 to use this for getValues

      for(int i=0; i<N; i++) {
      x[i] = IloArray<IloBoolVarArray> (env, N);
      for(int j=0; j<N; j++) {
      x[i][j] = IloBoolVarArray(env, color);
      }
      }
      IloArray<IloArray<IloExpr> > sumOfColors(env, N);

      for(int i=0; i<N; i++) {
      sumOfColors[i] = IloArray<IloExpr>(env, N);
      for(int j=0; j<N; j++) {
      sumOfColors[i][j] = IloExpr(env);
      }
      }
      for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
      for(int k=0; k<color; k++) {
      sumOfColors[i][j] += x[i][j][k];
      }
      }
      }
      IloArray<IloArray<IloRange> > range_sumOfColors = IloArray<IloArray<IloRange> >(env, N);

      for(int i=0; i<N; i++) {
      range_sumOfColors[i] = IloArray<IloRange> (env, N);
      for(int j=0; j<N; j++) {
      range_sumOfColors[i][j] = IloRange(env, 1, sumOfColors[i][j], 1);
      }
      }
      IloArray<IloArray<IloExpr> > weightedSumBR = IloArray<IloArray<IloExpr> >(env, r);

      for(int i=0; i<r; i++) {
      weightedSumBR[i] = IloArray<IloExpr>(env, r);
      for(int j=0; j<color; j++) {
      for(int k=i*n; k<(i+1)*n; k++) {
      for(int l=0; l<N; l++) {
      weightedSumBR[i][j] += m[k][l]*x[k][l][j];
      }
      }
      }
      }

      IloArray<IloArray<IloRange> > range_weightedSumBR(env, r);

      for(int i=0; i<r; i++) {
      IloArray<IloRange> range_weightedSumBR[i] = IloArray<IloRange>(env, r);
      for(int j=0; j<color; j++) {
      IloRange range_weightedSum_BR[i][j] = IloRange(env, 0, weightedSum_BR[i][j], addupto);
      }
      }
      IloArray<IloArray<IloExpr> > weightedSumBC(env, r);

      for(int i=0; i<r; i++) {
      weightedSumBC[i] = IloArray<IloExpr>(env, r);
      for(int j=0; j<color; j++) {
      for(int k=0; k<N; k++) {
      for(int l=i*n; l<(i+1)*n; l++) {
      weightedSumBC[i][j] += m[k][l]*x[k][l][j];
      }
      }
      }
      }
      IloArray<IloArray<IloRange> > range_weightedSumBC(env, r);

      for(int i=0; i<r; i++) {
      range_weightedSum_BC[i] = IloArray<IloRange> (env, r);
      for(int j=0; j<color; j++) {
      range_weightedSum_BC[i][j] = IloRange(env, 0, weightedSum_BC[i][j], addupto);
      }
      }

      model.add(range_SumOfColors);
      model.add(range_weightedSumBR);
      model.add(range_weightedSumBC);

      IloCplex cplex(env);
      cplex.extract(model);
      cplex.solve();
      cplex.out() << "solution status = " << cplex.getStatus() << endl;
      cplex.out() << endl;

      for(int i=0; i<5; i++) {
      cplex.out() << cplex.getValues(x) << endl;
      }
      if (cplex.getStatus() == IloAlgorithm::Infeasible){
      // cplex.out() << endl << "*** the model is not infeasible ***" << endl;

      ofstream outdata;
      outdata.open("badmatrix.csv");
      if (!outdata){cerr << "Error: file could not be opened" << endl;
      exit(1);}
      else{
      size_t it1;
      size_t it2;
      size_t n = m.size();
      for (it1=0;it1<n;it1++){
      for (it2 = 0; it2<n; it2++){
      outdata << matrit1it2 << endl;}}
      }
      outdata.close();
      env.end();
      cplex.out() << "Infeasible matrix detected" << endl;
      return 6;
      }
      }
      catch(IloException& e) {
      cerr << " ERROR: " << e << endl;
      }
      catch(...) {
      cerr << " ERROR: " << endl;
      }
      env.end();
      return 5;
      }