error "line 34 :"demandNc is already defined"

18 views
Skip to first unread message

曾婷婷

unread,
Oct 19, 2016, 5:02:39 PM10/19/16
to am...@googlegroups.com
hi!
Enclosed is my .mod and .dat files inside which you can find more marks to make it more easily to understand my quetsions.

basically it's about 2 questions.
1  error "line 34 (offset 2134):"demandNc is already defined"
2  if I block line 34, I got no error until after "solve" 
    "Error executing "solve" command: error processing constraint timecontinuity[0,5,7]: invalid subscript         Occupiedservicetimestep[0,7]".
    Well in my .dat, Occupiedservicetimestep[0,7] is valid.

hope to get your help quite soon:) 

曾婷婷

unread,
Oct 19, 2016, 5:05:12 PM10/19/16
to am...@googlegroups.com
Sorry I sent it out before finishing it by accident :)
here you go.
Thanks:)
12.dat
12.mod

Robert Fourer

unread,
Oct 20, 2016, 5:10:47 PM10/20/16
to am...@googlegroups.com

(1) If your write

 

  param demandNc {Sectorofvessel} >= 0;

 

and then later in the model you write

 

  param demandNc {i in Vessel} = sum {m in Sectorofvessel:originofsectorvessel[m]=i} demandNc[m];

 

then you have defined demandNc twice, and AMPL will give a "demandNc is already defined" error for the second definition.  Probably you want demandNc to be defined by the expression to the right of the = sign; in that case, you should use only the second definition in your model, and not the first one.  (If you want to make a one-time assignment of the expression to demandNc, then use the first definition in your model, and then *after* reading the model and the data, execute

 

  let {i in Vessel} demandNc[i] := sum {m in Sectorofvessel:originofsectorvessel[m]=i} demandNc[m];

 

This is probably not want you want to do, however, unless you have a complex AMPL command script.)

 

(2) Your model defines

 

  var Occupiedservicetimestep

    {i in Vessel,t in Timestep: t <= timeamount-servicehour[i]+1 and t >= arrivaltime[i]} binary;

 

AMPL's display command can be used to view the indexing set for this variable:

 

  ampl: display {i in Vessel,t in Timestep: t <= timeamount-servicehour[i]+1 and t >= arrivaltime[i]};

  set {i in Vessel, t in Timestep: t <= timeamount - servicehour[i] + 1 && t >=

    arrivaltime[i]}  :=

 (0,0)   (0,3)   (0,6)   (1,4)   (2,1)   (2,4)   (3,2)   (3,5)

 (0,1)   (0,4)   (1,2)   (1,5)   (2,2)   (2,5)   (3,3)   (3,6)

 (0,2)   (0,5)   (1,3)   (1,6)   (2,3)   (2,6)   (3,4);

 

You can see that (0,7) is not in this set, and that is why the reference to Occupiedservicetimestep[0,7] in your constraint timecontinuity[0,5,7] is rejected with an "invalid subscript" error.

 

Bob Fourer

am...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Tingting

unread,
Oct 24, 2016, 9:15:01 AM10/24/16
to AMPL Modeling Language, 4...@ampl.com
Hi Bob.
I was not informed of your reply and thought you were busy with something else. I just checked it out. What a surprise and Thanks!
1 For the already defined issue, I solved it by change demandNc {Sectorofvessel} into demandNcm {Sectorofvessel}

param demandNcm {Sectorofvessel} >= 0;

param demandNc {i in Vessel} = sum {m in Sectorofvessel:originofsectorvessel[m]=i} demandNcm[m];

Thus i have defination to both demandNc[i] and demandNcm[m].

2 For var Occupiedservicetimestep, yes I got the matrix. 

So in this case, we have binary value for variables inside the matrix. For those not inside, take (0,7) for example, it should be just 0. 

My question is: how to tell ampl that just figure our values inside the matrix to be 0 or 1, considering those outside values to be 0?

Reply all
Reply to author
Forward
0 new messages