## how to control the number of variables

Problems with modeling
yanzhiping
User
Posts: 85
Joined: 1 year ago

### how to control the number of variables

I have a problem as following:

Code: Select all

``````set A
A1(A)
A2(A)

B
B1(B)
B2(B)
B3(B)
variable
P(A,B)``````
In this case, variable p is related to all the combination of A and B. but actually only P(A1,B1) and P(A2,B2), P(A,B3) are nonzero.
there are a lot of fixed zero variables for P(A1,B2), P(A2,B1).

How may I define a variable with only non-zero values?

Manassaldi
User
Posts: 58
Joined: 1 year ago
Location: Rosario - Argentina

### Re: how to control the number of variables

Hi, the final number of variables depends on the constraints.

User
Posts: 108
Joined: 1 year ago

### Re: how to control the number of variables

For more detail: You don't need to declare the domain of the variable (as in variable P(A,B)). You can just write variable p;

Then, if the variable appears in the constraints, it will be part of the model. Check out this example:

Code: Select all

``````sets A /1*5/
A1(A) /2,3/

variable d,t;

equation Q,dummy;

Q(A1).. d(a1) =E= 0;
dummy.. t=l=2;

model p /all/;

solve p using lp maximizing t``````

yanzhiping
User
Posts: 85
Joined: 1 year ago

### Re: how to control the number of variables

this works well. thanks a lot.