# How define variable in CPLEX and What is diffrence between decision variables and variable in CPLEX

I want to code a problem by CPLEX, in this problem I have variables and decision variables, how define them?

In this picture you can see the variables: which we have:

I use these codes for variables:

//Variables

float Q[periods]; //Inventory of the blood product at the blood center in time period t after receiving the quantity produced in time period t 1, allocating the delivered quantity to hospitals and disposing of the expired quantity

float W[periods]; //Quantity of expired blood product at the blood center in time period t

float I[hospitals][periods]; //Inventory level of the blood product at hospital i in time period t after receiving the delivered quantity and usage and i > 0

float G[hospitals][periods]; //Shortage quantity at hospital i in time period t

//Decision Variable

dvar float+ p[periods]; //Quantity of the blood product produced at the blood center in time period t

dvar boolean y[nodes][vehicles][periods]; //A binary variable, if hospital i is served by vehicle k in time period t, y = 1 ; otherwise, y = 0

dvar float+ dq[hospitals][vehicles][periods]; //Quantity of the blood product delivered to hospital i by vehicle k in time period t

dvar float+ pq[hospitals][vehicles][periods]; //Quantity of the blood product picked up from hospital i by vehicle k in time period t

dvar boolean x[nodes][nodes][vehicles][periods]; //A binary variable, if the delivery vehicle k travels from node i to node j in time period t, x = 1 ; otherwise, x = 0

dvar float+ tq[nodes][nodes][vehicles][periods]; //Quantity of the blood product transported by vehicle k trough arc (i, j) in time period t

dvar float+ xq[nodes][nodes][vehicles][periods]; //An auxiliary variable for linearization

dvar boolean b[periods]; //An auxiliary binary variable for linearization

dvar float+ Z; //An auxiliary variable for linearization


Is it correct or not? what is the difference between decision variables and variables in coding in CPLEX?

as can be read in OPL CPLEX documentation, A decision variable is an unknown in an optimization problem.

For instance

dvar int x in 0..10;


is a decision variable

int a=3;


is some data definition whereas in

execute
{
var b=2;
}


b is a scripting variable.

float Q[periods]; //Inventory of the blood product at the blood center in time period t after receiving the quantity produced in time period t 1, allocating the delivered quantity to hospitals and disposing of the expired quantity

float W[periods]; //Quantity of expired blood product at the blood center in time period t

float I[hospitals][periods]; //Inventory level of the blood product at hospital i in time period t after receiving the delivered quantity and usage and i > 0

float G[hospitals][periods]; //Shortage quantity at hospital i in time period t


which are data.

But if you keep the model like this all the Q,W,I,G will be 0 so those should either be defined through a formula or in extension.

int Q[1..2]=[4,5];     // in extension
int Q2[i in 1..2]=i+3; // formula

assert forall(i in 1..2) Q[i]==Q2[i];

• p in Q formulation is decision variable and CPLEX couldn't accept this, how could I define formulation? Feb 19 at 12:04
• could you answer this question,@Alex Fleischer? Feb 19 at 18:57