-1

First of all, thank you for all readers.

The problem as below.

int MaxANum = 5;
int MaxBNum = 3;
int MaxENum = 8;

int ANum = 3;
int BNum = 2;
int ENum = 5;

range TTRange = 1..(MaxANum+MaxBNum);
range TRange = 1..(ANum+BNum);
range ARange = 1..ANum;
range BRange = 1..BNum;

range TERange = 1..MaxENum;
range ERange = 1..ENum;

M[TTRange][TERange] = [[**0, 1, 1, 0, 1**, 1, 0, 1] -> 1st ANum
                    [**1, 1, 0, 0, 1**, 0, 0, 1] -> 2nd ANum
                    [**0, 0, 1, 0, 1**, 0, 1, 0] -> 3rd ANum
                    [0, 1, 0, 0, 1, 1, 1, 0] -> 4th ANum
                    [1, 1, 0, 1, 0, 1, 0, 1] -> 5th ANum
                    [**1, 0, 0, 1, 1**, 0, 0, 0] -> 1st BNum
                    [**0, 0, 1, 0, 0, 0**, 1, 1] -> 2nd BNum
                    [1, 1, 0, 0, 0, 0, 0, 1]]; -> 3rd BNum

In this situation, I'd like to reform the matrix by selecting certain lows and columns.

Like as...

M1[TRange][ERange] = [[0, 1, 1, 0, 1] -> 1st ANum
                    [1, 1, 0, 0, 1] -> 2nd ANum
                    [0, 0, 1, 0, 1] -> 3rd ANum
                    [1, 0, 0, 1, 1] -> 1st BNum
                    [0, 0, 1, 0, 0] -> 2nd BNum

I am the beginner of CPLEX and computer coding. Plz, let me know, how to I get a code for this. Thank you for your reading so much.

1 Answers1

2

I am not quite sure how your input is related to the desired output but this code snippet may help:

range TTRange = 1..8;
range TRange = 1..5;
range TERange = 1..8;
range ERange = 1..5;

int M[TTRange][TERange] = [[0, 1, 1, 0, 1, 1, 0, 1],
                           [1, 1, 0, 0, 1, 0, 0, 1],
                           [0, 0, 1, 0, 1, 0, 1, 0],
                           [0, 1, 0, 0, 1, 1, 1, 0],
                           [1, 1, 0, 1, 0, 1, 0, 1],
                           [1, 0, 0, 1, 1, 0, 0, 0],
                           [0, 0, 1, 0, 0, 0, 1, 1],
                           [1, 1, 0, 0, 0, 0, 0, 1]];

int M1[t in TRange][e in ERange] = M[t][e];

It produces this sub-matrix:

 M1 = [[0 1 1 0 1]
       [1 1 0 0 1]
       [0 0 1 0 1]
       [0 1 0 0 1]
       [1 1 0 1 0]]

The "trick" is to do the selection in the index sets of M1.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22