converting a non binary matrix into a binary matrix

I have a 4x3 matrix with numbers from 0 to 10 and I want to convert it to a 4x3 matrix with binary numbers, so any number >=1 in the original matrix becomes a 1, and all 0's stay as 0 in the new matrix.

I have managed to make it work in Excel by two different ways: a simple way using the IF function (I had to change the Solver method) and more complex way calculating the Lane pairs combinations and doing some arithmetics with them, something logically and unfortunately only valid for this specific example (so kind of useless).

In SAS, with a 4x1 matrix I was able to do it by using a linking constraint. Quick example:

Those numbers where the sum{i in DC}flow[i,j] >0 will be forced to become 1, and for those <=0 the optimization will choose to make them become 0 in the OPEN 4x1 binary matrix since I am minimising and each 1 in the OPEN variable would add a fixcost to the totalcost function. This method allow me also to specify the maximum number of DC to use thanks to the Pmax (or the minimum with an additional constraint).

However, now I am dealing with a 4x3 matrix and my linking constraint doesn't seem to work since the model can now assign the 0's to any other column of the matrix when I specify a Pmax or a Pmin.

Re: converting a non binary matrix into a binary matrix

Your linking constraint enforces the logical implication: if PackBin[j,k]*Loads[i,k] > 0 for some k then IsCarrier[j,i] = 1. Without the MinCarriersPerLane constraint, the objective would naturally enforce the converse implication: if IsCarrier[j,i] = 1 then PackBin[j,k]*Loads[i,k] > 0 for some k. But the MinCarriersPerLane constraint encourages the solver to "cheat" in the way you identified. You can explicitly enforce the desired implication as follows:

con linkingcon2{j in Lane, i in Carrier}:
Usecarrier[j,i] <= sum{k in Pack}PackBin[j,k]*Loads[i,k];

Also note that you don't need to declare the dummy constraints Real_Cost and cons1. Instead, you can declare an implicit variable, which you can then reuse in the objective declaration:

Re: converting a non binary matrix into a binary matrix

Your linking constraint enforces the logical implication: if PackBin[j,k]*Loads[i,k] > 0 for some k then IsCarrier[j,i] = 1. Without the MinCarriersPerLane constraint, the objective would naturally enforce the converse implication: if IsCarrier[j,i] = 1 then PackBin[j,k]*Loads[i,k] > 0 for some k. But the MinCarriersPerLane constraint encourages the solver to "cheat" in the way you identified. You can explicitly enforce the desired implication as follows:

con linkingcon2{j in Lane, i in Carrier}:
Usecarrier[j,i] <= sum{k in Pack}PackBin[j,k]*Loads[i,k];

Also note that you don't need to declare the dummy constraints Real_Cost and cons1. Instead, you can declare an implicit variable, which you can then reuse in the objective declaration:

I will make good use of the impvar and stop defining dummy constraints ;-)

I see that the additional linkingcon2 is enforcing correctly the number of minimum Carriers per Lane to use and it is exactly what I needed.

I used the uselinecost in order to make the linkingcon constraints work (it wasn't a requirement of the exercise), and I had to change the values to 1's in order to obtain the real minimum cost:

number uselinecost{Lane,Carrier}=[
1 1 1
1 1 1
1 1 1
1 1 1];

I knew that the minimum was lower than the one I obtained with your modifications because for having 2 or more Carriers per Lane I used a simple Capacity constraint where each Carrier could provide only the demand per Lane required minus 1: