Re: [AMPL 12375] How to define a set with two parameters where value is binary

401 views
Skip to first unread message

Victor Zverovich

unread,
Jul 29, 2016, 2:29:24 PM7/29/16
to am...@googlegroups.com
From your descriptions, it looks like jobs and tools should be sets, not parameters, and matrix will be a parameter indexed over these two sets:

  set jobs;
  set tools;
  param use{jobs, tools} binary;
  data;
  set jobs := j1 j2 j3 j4;
  set tools := t1 t2 t3;
  param use:
       t1   t2    t3 :=
    j1  1    1     0
    j2  0    1    1
    j3  1    0    1
    j4  0    0    1;

HTH,
Victor

On Thu, Jul 28, 2016 at 9:35 AM biz <issab...@gmail.com> wrote:

Hello everyone ! I am new to AMPL and this is my first post, any suggestions or help is much appreciated


I have two parameters let's say job and tools and this matrix 


     t1   t2    t3

j1  1    1     0

j2   0    1    1

j3   1    0    1

j4   0    0    1


so here it means job1 can use either tool1 or tool2 to be processed , job2 can use either tool2 or tool3 .. etc , so my question is how to write this in AMPL 

and create a set let’s say set A; for this two parameters to be used in the following constraint 


{h in 1..H} : sum {m in 1..M,j in A} p[j,m] * X[j,h,m] <= TL[t] * TC[t];


where h is the number of periods, m number of modes ( different processing time and cost for different modes), 

      j is the number of jobs, and t is the number of tools , 

      X is binary decision variable. 

      TL and TC : capacity of tools for only tools in set A 


Any help is much appreciated

Thank you 

--
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.

biz

unread,
Jul 31, 2016, 7:43:29 AM7/31/16
to AMPL Modeling Language
Thank you Victor for your reply , it worked perfectly . 
If you don't mind, I have 2 small questions regarding the same problem , 
1.  I have created a random  binary matrix using this : param use{jobs, tools} = floor(Uniform(0,2)), 
    however , I want to have at least a '1' in each row in case all the values are , for ex : 
After generating the random binary matrix,  I got this result but I want to change the last row to have at least '1' in any position
        t1   t2    t3   t4 :=
    j1  1    1     0   1
    j2  0    1    1    0
    j3  1    0    1    0
    j4  0    0    0    0;

2. How could i transpose this matrix to another param lets say:  param use2{tools, jobs} to have the same value as above. 

Thank you in advance and appreciate your help. 

Victor Zverovich

unread,
Aug 1, 2016, 1:30:42 PM8/1/16
to am...@googlegroups.com
1. You can use the let statement to assign values to parameter ``use`` instead of doing it in the initializer:

  param use{jobs, tools};
  let{j in jobs, t in tools} use[j, t] := floor(Uniform(0,2));
  let use['j4', 't1'] := 1;

2. You can define a transposed version of ``use`` as follows:

  param use2{t in tools, j in jobs} = use[j, t];

HTH,
Victor
Reply all
Reply to author
Forward
0 new messages