I want to declare a variable over a dynamic set; however I receive the
error massage of “assigned set used as domain”. It’s important for me
to declare the variables over that subset, because I’m using PATH
solver for complementarity conditions and the number of declared
variables should be exactly the same as the number of constraints in
order to have a square matrix.
I understand that dynamic sets cannot be used as domain, but is there
any way that I can bypass this limit.Let’s say I have the following
code:
set i /1*1000/
set gen(i);
parameter condGen(i);
condGen(i)=round(Uniform(0,3));
gen(i)=yes$(condGen(i)=2);
variable test(gen);
Is there any way I can declare the “test” variable over the subset of
gen, other than the whole set of i?
I appreciate your help.
Thanks,
M.Pirnia
\
M.Pirnia,
You do not want to declare the variables over a dynamic set, but
rather use them in the model in such a way that they only exist for
members of your dynamic set. For example, do this:
set i /1*1000/
set gen(i);
variable test(i);
equation genLim(i);
genLim(gen(i))… test(i) =L= someFunction(i);
This will only generate equations and variables for i in gen(i).
To repeat, your strategy should be: declare variables and equations
over static sets, but define the equations and use the variables over
the dynamic sets to appropriately limit the variables and equations
that actually exist.
-Steve
On Mon, Mar 28, 2011 at 7:58 PM, m.pirnia wrote:
I want to declare a variable over a dynamic set; however I receive the
error massage of “assigned set used as domain”. It’s important for me
to declare the variables over that subset, because I’m using PATH
solver for complementarity conditions and the number of declared
variables should be exactly the same as the number of constraints in
order to have a square matrix.
I understand that dynamic sets cannot be used as domain, but is there
any way that I can bypass this limit.Let’s say I have the following
code:
set i /1*1000/
set gen(i);
parameter condGen(i);
condGen(i)=round(Uniform(0,3));
gen(i)=yes$(condGen(i)=2);
variable test(gen);
Is there any way I can declare the “test” variable over the subset of
gen, other than the whole set of i?
I appreciate your help.
Thanks,
M.Pirnia
–
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)342-0180 Fax: (202)342-0181 sdirkse@gams.com http://www.gams.com
Thanks for your reply Steven,
As you mentioned, limiting equations over the dynamic sets is pretty
straight forward; however my main problem is defining variables over
the dynamic sets. It’s somehow problematic in my model because the
equations for some constraints involve many variables. To make it more
clear let’s say, I have the following code:
set i /1*5/
set dynamicSet(i);
parameter cond(i) /1 1,2 1,3 2,4 1,5 2/;
dynamicSet(i)=yes$(cond(i)=2);
variable testVar1(i),testVar2(i);
equation testEq1(i),testEq2(i);
testEq1(i)… testVar1(i)-testVar2(i)=l=7;
testEq2(dynamicSet(i))… testVar1(i)+testVar2(i)=l=3;
model testModel/testEq1.testVar1
testEq2.testVar2/
solve testModel using mcp;
As shown above, the first constraint involves all the two variables.
and therefore we end up having 10 variables in the model since the
first constraint is defined over all i. We have 2 equations for
testEq2 constraint, since it’s limited to dynamicSet; however because
I already have testVar2 in testEq1, I have 5 testVar2 variables,
causing a non-square model and therefore doesn’t let Path to solve it.
Breaking the equations or variables is not an option since my
equations are complicated.
I appreciate if you let me know, whether there is a way to create a
square matrix under these conditions.
Thanks,
On Mar 29, 9:20 am, Steven Dirkse wrote:
M.Pirnia,
You do not want to declare the variables over a dynamic set, but
rather use them in the model in such a way that they only exist for
members of your dynamic set. For example, do this:
set i /1*1000/
set gen(i);
variable test(i);
equation genLim(i);
genLim(gen(i))… test(i) =L= someFunction(i);
This will only generate equations and variables for i in gen(i).
To repeat, your strategy should be: declare variables and equations
over static sets, but define the equations and use the variables over
the dynamic sets to appropriately limit the variables and equations
that actually exist.
-Steve
On Mon, Mar 28, 2011 at 7:58 PM, m.pirnia wrote:
I want to declare a variable over a dynamic set; however I receive the
error massage of “assigned set used as domain”. It’s important for me
to declare the variables over that subset, because I’m using PATH
solver for complementarity conditions and the number of declared
variables should be exactly the same as the number of constraints in
order to have a square matrix.
I understand that dynamic sets cannot be used as domain, but is there
any way that I can bypass this limit.Let’s say I have the following
code:
set i /1*1000/
set gen(i);
parameter condGen(i);
condGen(i)=round(Uniform(0,3));
gen(i)=yes$(condGen(i)=2);
variable test(gen);
Is there any way I can declare the “test” variable over the subset of
gen, other than the whole set of i?
I appreciate your help.
Thanks,
M.Pirnia
–
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)342-0180 Fax: (202)342-0181
sdir…@gams.comhttp://www.gams.com
\
M.Pirnia,
Short version: change your equation definition from
testEq1(i)… testVar1(i) - testVar2(i) =L= 7;
to
testEq1b(i)… testVar1(i) - testVar2(i)$dynamicSet(i) =L= 7;
It has been suggested many times that we introduce a way to declare a
variable so there is a restriction on the tuples that appear. For
example, if we said
variable testVar2(dynamicSet(i));
then all occurrences of testVar2(i) would act like we had written
testVar2(i)$dynamicSet(i). I won’t get into the reasons we haven’t
done this, but it sounds like that’s what you’re looking for.
Unfortunately, you can’t do this directly.
Here’s a working model showing the failing and working instances.
-Steve
set i /1*5/
set dynamicSet(i);
parameter cond(i) /1 1,2 1,3 2,4 1,5 2/;
dynamicSet(i)=yes$(cond(i)=2);
variable testVar1(i),testVar2(i);
equation testEq1(i),testEq2(i),testEq1b(i);
testEq1(i)… testVar1(i) - testVar2(i) =L= 7;
testEq1b(i)… testVar1(i) - testVar2(i)$dynamicSet(i) =L= 7;
testEq2(dynamicSet(i))… testVar1(i)+testVar2(i) =L= 3;
model testModel / testEq1.testVar1
testEq2.testVar2 /;
model test2 / testEq1b.testVar1
testEq2.testVar2 /;
maxexecerror = 1;
solve testModel using mcp;
abort$[not execerror] ‘unmatched testVar2 should trigger error’;
execerror = 0;
solve test2 using mcp;
abort$[execerror] ‘test2 should be working’;