Replyto: gamsworld@googlegroups.com
Hi all,
Now I have a matrix variable and I want to fix some of them.
For example, the variable is a matrix of z(2,3). I want to fix the items z(1,2)=1 and z(2,1)=0. Notice these fixed items are not a rectangle/square submatrix, just some randomly picked items. The variable z looks like below:
[ X 1 X]
[ 0 X X]
X means the items need to be solved.
Which items should be fixed are given by Matlab. And the fixed values are also given by Matlab.
How to pass these information to GAMS in correct format by GDXXRW or WGDX or call gams in Matlab?
I tried to use z.FX (si, sj) = level (si, sj), but I can’t figure out the correct form of si and sj
Thanks.
–
Best regards,
Peng (Dennis) Wei
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
Peng,
My suggestion to you follows the typical pattern for most suggestions
I make re: interfacing GAMS and Matlab: divide and conquer. Split the
problem up into smaller pieces and solve them individually. When you
get more proficient you can take shortcuts, but not starting out.
 Create a small GAMS model that implements a solution to your
problem, and that uses data to solve it. There are two ways I’d
suggest.
1a: a set specifying where to fix and a parameter of values to fix to.
set I / i1 * i2 /, J / j1 * j3 /, fixer(I,J) / i1.j2, i2.j1/;
parameter zfix(I,J) / i1.j2 0, i2.j1 1/;
variable z(I,J);
z.fx(fixer) = zfix(fixer);
1b: use just a parameter to fix. This is a bit more subtle because it
uses the GAMS eps value.
set I / i1 * i2 /, J / j1 * j3 /;
parameter zfix(I,J) / i1.j2 eps, i2.j1 1/;
 GAMS will not store a zero, but it stores the eps and that fixes the
corresponding tuple to 0.
variable z(I,J);
z.fx(I,J)$zfix(I,J) = zfix(I,J);

generate the correct matlab code to create the set and parameter
from 1a or just the parameter from 1b and write them to a GDX file.
Use the GDX viewer in the IDE or gdxdump to verify you have what you
want in the GDX file.

Read in the data from the GDX file instead of specifying it in
GAMS, using $gdxin & $load.
HTH,
Steve
On Thu, Apr 7, 2011 at 11:50 AM, Peng Wei wrote:
Hi all,
Now I have a matrix variable and I want to fix some of them.
For example, the variable is a matrix of z(2,3). I want to fix the items
z(1,2)=1 and z(2,1)=0. Notice these fixed items are not a rectangle/square
submatrix, just some randomly picked items. The variable z looks like below:
[ X 1 X]
[ 0 X X]
X means the items need to be solved.
Which items should be fixed are given by Matlab. And the fixed values are
also given by Matlab.
How to pass these information to GAMS in correct format by GDXXRW or WGDX or
call gams in Matlab?
I tried to use z.FX (si, sj) = level (si, sj), but I can’t figure out the
correct form of si and sj
Thanks.
–
Best regards,
Peng (Dennis) Wei
–
“gamsworld” group.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to
gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/gamsworld?hl=en.
– Steven Dirkse, Ph.D. GAMS Development Corp., Washington DC Voice: (202)3420180 Fax: (202)3420181 sdirkse@gams.com http://www.gams.com
When setting .fx or just setting .lo and .up to the same value for a
variable, will GAMS then treat it as a parameter (i. e. not spend time
on finding values for the variable)? What about an equation fixing the
variable, like eq … x =e= 1;?
Best regards,
Erik Lien Johnsen
\
Erik,
It’s important to be aware of a separation that exists between
GAMS/Base (the piece that constructs the model) and the solvers
themselves (the code that actually does the optimization). Some
solvers can behave differently on the original model vs. a model with
fixed variables removed and trivial equations fixing variables taken
out. And once you start down the road of presolving the model in
GAMS, there lots of lesstrivial presolving steps that can be done.
These are more likely to change solver behavior. For these reasons,
GAMS’ default behavior is to pass the model on to the solver as
formulated by the user. Most solvers, especially for LPs and MIPs,
implement a presolve so they will remove fixed variables and equations
and do plenty of other things in their presolve as well, so in
practice fixed variables are often ignored. The output typically
shows the size of the model before and after presolve in this case.
There is an option in GAMS/Base to remove fixed variables. It is off
by default. Setting
myModel.holdFixed = 1;
will make GAMS/Base remove fixed variables from the model, but it
still will leave in “fixing” equations. If holdfixed=1, you won’t get
dual values for the fixed variables.
Steve
On Mon, Apr 11, 2011 at 3:58 PM, Erik Lien Johnsen
wrote:
When setting .fx or just setting .lo and .up to the same value for a
variable, will GAMS then treat it as a parameter (i. e. not spend time
on finding values for the variable)? What about an equation fixing the
variable, like eq … x =e= 1;?
Best regards,
Erik Lien Johnsen
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.
– Steven Dirkse, Ph.D. GAMS Development Corp., Washington DC Voice: (202)3420180 Fax: (202)3420181 sdirkse@gams.com http://www.gams.com
Thank you, Steve.
If the solution of the model with holdfixed=1 is dramatically
different from the solution with holdfixed=0 (and I am using BARON,
which is supposed to find the global optimum), how should I interpret
this? (The number of variables reported by GAMS/BARON is reduced from
165 to 161, ‘non zero elements’ from 753 to 693, ‘non linear nz’ from
250 to 231, and the ‘constant pool’ is increased from 342 to 345 and I
am working with MINLP.)
Best regards,
Erik Lien Johnsen
On 12 apr, 17:51, Steven Dirkse wrote:
Erik,
It’s important to be aware of a separation that exists between
GAMS/Base (the piece that constructs the model) and the solvers
themselves (the code that actually does the optimization). Some
solvers can behave differently on the original model vs. a model with
fixed variables removed and trivial equations fixing variables taken
out. And once you start down the road of presolving the model in
GAMS, there lots of lesstrivial presolving steps that can be done.
These are more likely to change solver behavior. For these reasons,
GAMS’ default behavior is to pass the model on to the solver as
formulated by the user. Most solvers, especially for LPs and MIPs,
implement a presolve so they will remove fixed variables and equations
and do plenty of other things in their presolve as well, so in
practice fixed variables are often ignored. The output typically
shows the size of the model before and after presolve in this case.
There is an option in GAMS/Base to remove fixed variables. It is off
by default. Setting
myModel.holdFixed = 1;
will make GAMS/Base remove fixed variables from the model, but it
still will leave in “fixing” equations. If holdfixed=1, you won’t get
dual values for the fixed variables.
Steve
On Mon, Apr 11, 2011 at 3:58 PM, Erik Lien Johnsen
wrote:
When setting .fx or just setting .lo and .up to the same value for a
variable, will GAMS then treat it as a parameter (i. e. not spend time
on finding values for the variable)? What about an equation fixing the
variable, like eq … x =e= 1;?
Best regards,
Erik Lien Johnsen
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/gamsworld?hl=en.
–
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)3420180 Fax: (202)3420181
sdir…@gams.comhttp://www.gams.com
\