[AMPL 25061] subejct to is not working after another subject to

Hey guys,

currently Im working on an task which needs multiple subject to commands.

this is my mod:

param J; # Anzahl der Produkte
param T; # Anzahl der Perioden

set j := 1..J;
set t := 1..T;
set j0:=0;

param d{j,t}; # Nachfrage nach Produkt j in Periode t
param I0; # Anfangslagerbestand des Produktes j
param s{j}; # Rüstkostensatz des Produktes j
param h{j}; # Lagerhaltungskostensatz des Produktes j
param C{t}; # Verfügbare Kapazität in Periode t
param p{j}; # Produktionskoeffizient des Produktes j

var q{j,t} >= 0; # Produktionsmenge von j in Periode t
var x{j,t} binary; # 1 wenn in Periode t für j gerüstet wird, sonst 0
var I{j,t} >= 0; # Lagerbestand von Produkt j am Ende der Periode t

minimize costs: 
   sum {a in J, b in T} (s[a] * x[a,b] + h[a] * I[a,b]);

subject to Lager {a in J, b in T}: 
   (if a = 1 then 0 else I[a-1,b]) + q[a,b] - d[a,b] = I[a,b];

subject to Kapazität {a in J, b in T}: 
   p[a] * q[a,b] <= C[a] * x[a,b];

subject to Lager seems to be alright because first i couldnt do another subejct to command after it, but when i fixed it, it turned out to be right, because then another subejct to command was possible.

But now it seems that something is wrong with subject to Kapazität, because i cant put in another subject to command after that one, which shows me that something is incorrect but so far I couldnt figure out the mistake.

Help ASAP pls :slight_smile:

Anwar

This part of your model already has 4 error messages:

syntax error
context:  set  >>> j0:=0; <<< 

syntax error
context:  sum {a in  >>> J, <<<  b in T} (s[a] * x[a,b] + h[a] * I[a,b]);

syntax error
context:  subject to Lager {a in  >>> J, <<<  b in T}: 

syntax error
context:  subject to Kapazität {a in  >>> J, <<<  b in T}: 

The first one occurs because you are assigning a number to a set. If you need to define a set whose only member is the number 0, you should write:

set j0 := {0};

The other errors occur because you are writing a in J where J is a parameter. You need to say that a is in a set; in your case, a in j would be correct. Then you will find that there is the same problem with b in T, which you can correct similarly.

After these errors are fixed, you should find that AMPL goes on to read other “subject to” statements in your model.

Your question has been moved to our new user forum at discuss.ampl.com, and a response has been posted there. To see the response, use this link:

https://discuss.ampl.com/t/ampl-25061-subejct-to-is-not-working-after-another-subject-to/1971/2

To reply, click the red “Reply” button that follows the response. (Do not send an email reply to this message.)

Thanks for your quick reply. But unfortunately it is not working. I think the Mistake is specially in the second subject to, because commands are working perfectly after the first subject to, but after the second one none of the ampl commands work. But i corrected the mistakes that you already sorted out for me.

Hoping for another quick reply.

Thanks in advance.

Anwar

First, check whether you are still getting any error messages when you read the model into AMPL. An error in one subject to statement can cause later model statements to be ignored. After you fix the error (and any other errors in the same statement), later model statements will be processed.

If you have an error you can’t fix, or if the model does not seem to be processed correctly even though no errors appear, then post the entire current version of your model — including any previous fixes you have made. Also, if you see any AMPL messages when you try to read in the model, post the complete text of all messages.