Originally posted by: SystemAdmin
> in case1(test1.m),'x2' is not shown in obj or constraints;
'x2' does show up in the test1.lp file. It is present in the 'c4' constraint - 'c4 :+1.000000x2+2.000000x3=6.000000'. It is not present in the objective function since the co-efficient of c is 0 per your 'f' variable (f=
1;0;-3;5;1; in the test1.m file).
> no warning in matlab,
> and in Cplex class(cplex1),'x2' shown in cplex.Model.colname, but not
> the 2nd variable, why?
'x5' is not part of the constraints but is part of the objective function.
Since 'x2' and 'x5' are fixed to certain values, but are atleast present in the obj and/or the constraints, there are no warnings while reading in the 'test1.lp' file. Now, once you read in the model to a certain Cplex object, it is not guaranteed that the variable order will be the same as you intended it to be. This is because the solver could have rules which puts variables of a certain type together and thus the ordering of the variables may be different when you originally created the lp file. In test1.lp, x2 and x5 variables are fixed and thus are indexed such that they appear last in the 'cplex.Model.colname' property as such:
val = x1 x3 x4 x5 x2
> in case2(test2.m),'x5' is not shown in obj or constraints;
> there is warning in MALTAB
In test2.lp, 'x5' is not part of the objective function or the constraints. It is just a variable that is fixed to a certain value (7) in the Bounds section of the LP file. You thus get a warning that 'x5' does not exist as explained in the other thread.
> and in Cplex class(cplex2), no 'x5' in cplex.Model.colname, why?
Since 'x5' is really not part of the model and has no influence in the way that the model gets solved, hence it is not considered as a valid (decision) variable and thus not part of the cplex.Model.colname property.
> BTW, how can I get the index of variables from cplex.Model.colname?
If you are reading in a model via a LP file (using the readModel function), there is no way to map the indexes of the variables of the Cplex class to the original model's variables (while writing out the LP file). As mentioned above, the ordering of the variables is not part of the LP format and thus the solver may read the variables differently during the readModel call. If you absolutely want to preserve the ordering of the variables, you should use the Cplex class APIs instead of the toolbox functions (like x = cplexlp(f,Aineq,bineq,Aeq,beq,lb,ub,x0,options)
), wherein there are methods for data manipulation along with the ability to create and modify models. You may want to go through the examples that come with the distribution (say lpex1.m under the <CPLEX_StudioXXX>\cplex\examples\src\matlab folder) to get you started.
Hope this helps and explains.
#CPLEXOptimizers#DecisionOptimization