[AMPL 2088] Sum of certain elements of a set

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[AMPL 2088] Sum of certain elements of a set

louispat.dansereau

Hello!
I'm having some difficulties with a constraint in AMPL (and a couple
of others but with the same structure). I was using this constraint in
LINGO and it was working fine, but now that I'm using AMPL, it does
not work anymore. Can anyone help me with this one?

In my MILP scheduling problem, I have an inventory of different paper
grades and I must decide when to ship a fixed quantity of a certain
grade of paper to a customer. The customer asks that the shipment must
be sent in a time window. I have a constraint that specifies that
there cannot be a shipment before the time window starts. (Cannot send
paper during time period (days) 1 to 5 if time window starts at day
6).

here are some parts of my code

--------------------------------------
set PaperGrade ; #k
set Customer ; #m
set Time ordered ; #t

param T_start {Customer} >=0; # Beginning of the time window of order
m
param Km {Customer} >=0; # Paper grade asked in customer order m

var f_pap_cst {PaperGrade,Customer,Time}; # qty of paper k sent to
customer m in period t

subject to Demand_time_min {m in Customer:T_start[m] > 1}:
        sum {t in Time:t >= 1 && t <= T_start[m], k in PaperGrade: k = Km
[m]}
        f_pap_cst[k,m,t] = 0;
--------------------------------------
The elements of the sets are strings

set PaperGrade := News42, News45, News48;
set Customer := m1 m2 m3 m4 m5 m6 m7 ;
Set Time := t1 t2 t3 t4 ; # etc. until t90

I thought that t, k and m were automatically specified as integers by
AMPL and were used as coordinates in matrixes. (This is how it works
in Lingo). However, it doesn't seem to be the case. If this is true,
then this is why I get syntax errors in that constraint : k (or t)
expects a string and T_start[m] or Km[m] is a number.

Does anyone have another way of formulating this constraint? If I
change Time and Customers sets to number (and transform Km to
strings), will that solve my problem?

Thanks for helping me!

Oh and by the way, does AMPL on Unix will be one day able to support
table links to Excel? I had huge data spreadsheets in Excel and I had
to transfer them to text files... I'm playing a lot with values in my
data and playing in a text file is not very convenient...

Louis

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

[AMPL 2091] Re: Sum of certain elements of a set

Paul A. Rubin

Try

subject to Demand_time_min {m in Customer : T_start[m] > 1}:
   sum {t in Time, k in PaperGrade : t >= 1 && t <= T_start[m] && k =
Km[m]}
       f_pap_cst[k,m,t] = 0;

/Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

[AMPL 2092] Re: Sum of certain elements of a set

Robert Fourer-2
In reply to this post by louispat.dansereau


You are right, if an index runs over a set of strings, then the values that it
takes are strings, and it can't be used as a number.  Rather than call your
times t1 through t90, you could define them as the numbers 1 through 90:

   param T integer > 0;
   set Time = 1..T;

You could similarly number the paper grades, or could leave PaperGrade as a set
of strings and define Km as a symbolic (string-valued) parameter:
   
   param Km {Customer} symbolic in PaperGrade;

Then your constraint could be:
 
   subject to Demand_time_min {m in Customer: T_start[m] > 1}:
  sum {t in 1..T_start[m]} f_pap_cst[Km[m],m,t] = 0;

for the data you will specify

   set PaperGrade := News42, News45, News48 ;
   set Customer := m1 m2 m3 m4 m5 m6 m7 ;
   param T := 90 ;

Bob Fourer
[hidden email]


> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: Wednesday, November 19, 2008 11:59 PM
> To: AMPL Modeling Language
> Subject: [AMPL 2088] Sum of certain elements of a set
>
>
> Hello!
> I'm having some difficulties with a constraint in AMPL (and a couple
> of others but with the same structure). I was using this constraint in
> LINGO and it was working fine, but now that I'm using AMPL, it does
> not work anymore. Can anyone help me with this one?
>
> In my MILP scheduling problem, I have an inventory of different paper
> grades and I must decide when to ship a fixed quantity of a certain
> grade of paper to a customer. The customer asks that the shipment must
> be sent in a time window. I have a constraint that specifies that
> there cannot be a shipment before the time window starts. (Cannot send
> paper during time period (days) 1 to 5 if time window starts at day
> 6).
>
> here are some parts of my code
>
> --------------------------------------
> set PaperGrade ; #k
> set Customer ; #m
> set Time ordered ; #t
>
> param T_start {Customer} >=0; # Beginning of the time window of order
> m
> param Km {Customer} >=0; # Paper grade asked in customer order m
>
> var f_pap_cst {PaperGrade,Customer,Time}; # qty of paper k sent to
> customer m in period t
>
> subject to Demand_time_min {m in Customer:T_start[m] > 1}:
> sum {t in Time:t >= 1 && t <= T_start[m], k in PaperGrade: k = Km
> [m]}
> f_pap_cst[k,m,t] = 0;
> --------------------------------------
> The elements of the sets are strings
>
> set PaperGrade := News42, News45, News48;
> set Customer := m1 m2 m3 m4 m5 m6 m7 ;
> Set Time := t1 t2 t3 t4 ; # etc. until t90
>
> I thought that t, k and m were automatically specified as integers by
> AMPL and were used as coordinates in matrixes. (This is how it works
> in Lingo). However, it doesn't seem to be the case. If this is true,
> then this is why I get syntax errors in that constraint : k (or t)
> expects a string and T_start[m] or Km[m] is a number.
>
> Does anyone have another way of formulating this constraint? If I
> change Time and Customers sets to number (and transform Km to
> strings), will that solve my problem?
>
> Thanks for helping me!
>
> Oh and by the way, does AMPL on Unix will be one day able to support
> table links to Excel? I had huge data spreadsheets in Excel and I had
> to transfer them to text files... I'm playing a lot with values in my
> data and playing in a text file is not very convenient...
>
> Louis
>



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

[AMPL 2095] Re: Sum of certain elements of a set

louispat.dansereau

Thanks for your help!
I made the changes you suggested and now, my model works.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---