Hi,
-- I am trying to define a binary variable as: # binary unit param I_unit_max; set U_no := {1..I_unit_max}; var X_U {U_no} binary; then use it as (part of main code): minimize z: 500*(X_U[1]*X_Am_c + X_U[2]*X_Am_g + X_U[3]*X_Am_k); s.t. CONS_E_1: sum {i in I_feed} X_x1_ce[i]*X_U[1] = 1*X_U[1]; s.t. CONS_E_2: sum {i in I_feed} X_x2_cd[i]*X_U[1] = 1*X_U[1]; s.t. CONS_E_3: sum {i in I_feed} X_x1_gi[i]*X_U[2] = 1*X_U[2]; s.t. CONS_E_4: sum {i in I_feed} X_x2_gh[i]*X_U[2] = 1*X_U[2]; s.t. CONS_E_5: sum {i in I_feed} X_x1_km[i]*X_U[3] = 1*X_U[3]; s.t. CONS_E_6: sum {i in I_feed} X_x2_kl[i]*X_U[3] = 1*X_U[3]; s.t. CONS_IE_7: X_U[1] + X_U[2] + X_U[3] >=1; Actually, I have three boxes and I want to arbitrarily choose one of them. Is it the right code? I expect that if X_U[1] takes 0 then ignore two s.t. [CONS_E_1, CONS_E_2]. If I compare with programming languages like C#, If I declare a binary var then in each line it takes a value 0 or 1. Here in AMPL I am not sure about the initialization. if a var defined get 0, it remains zero in all lines or changes? If change it's difficult to construct a logical block. 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 [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
A variable such as X_U[1] has the same value in all constraints.
Bob Fourer [hidden email] ======= From: [hidden email] [mailto:[hidden email]] On Behalf Of SG Sent: Wednesday, November 29, 2017 5:03 PM To: AMPL Modeling Language Subject: [AMPL 15250] Using a binary var I am trying to define a binary variable as: # binary unit param I_unit_max; set U_no := {1..I_unit_max}; var X_U {U_no} binary; then use it as (part of main code): minimize z: 500*(X_U[1]*X_Am_c + X_U[2]*X_Am_g + X_U[3]*X_Am_k); s.t. CONS_E_1: sum {i in I_feed} X_x1_ce[i]*X_U[1] = 1*X_U[1]; s.t. CONS_E_2: sum {i in I_feed} X_x2_cd[i]*X_U[1] = 1*X_U[1]; s.t. CONS_E_3: sum {i in I_feed} X_x1_gi[i]*X_U[2] = 1*X_U[2]; s.t. CONS_E_4: sum {i in I_feed} X_x2_gh[i]*X_U[2] = 1*X_U[2]; s.t. CONS_E_5: sum {i in I_feed} X_x1_km[i]*X_U[3] = 1*X_U[3]; s.t. CONS_E_6: sum {i in I_feed} X_x2_kl[i]*X_U[3] = 1*X_U[3]; s.t. CONS_IE_7: X_U[1] + X_U[2] + X_U[3] >=1; Actually, I have three boxes and I want to arbitrarily choose one of them. Is it the right code? I expect that if X_U[1] takes 0 then ignore two s.t. [CONS_E_1, CONS_E_2]. If I compare with programming languages like C#, If I declare a binary var then in each line it takes a value 0 or 1. Here in AMPL I am not sure about the initialization. if a var defined get 0, it remains zero in all lines or changes? If change it's difficult to construct a logical block. -- 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 [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
Thank you Robert.
On Thursday, November 30, 2017 at 7:19:40 PM UTC-5, Robert Fourer wrote: > A variable such as X_U[1] has the same value in all constraints. > > Bob Fourer > [hidden email] > > ======= > > From: [hidden email] [mailto:[hidden email]] On Behalf Of SG > Sent: Wednesday, November 29, 2017 5:03 PM > To: AMPL Modeling Language > Subject: [AMPL 15250] Using a binary var > > I am trying to define a binary variable as: > > # binary unit > param I_unit_max; > set U_no := {1..I_unit_max}; > > var X_U {U_no} binary; > > then use it as (part of main code): > > minimize z: 500*(X_U[1]*X_Am_c + X_U[2]*X_Am_g + X_U[3]*X_Am_k); > > s.t. CONS_E_1: sum {i in I_feed} X_x1_ce[i]*X_U[1] = 1*X_U[1]; > s.t. CONS_E_2: sum {i in I_feed} X_x2_cd[i]*X_U[1] = 1*X_U[1]; > > s.t. CONS_E_3: sum {i in I_feed} X_x1_gi[i]*X_U[2] = 1*X_U[2]; > s.t. CONS_E_4: sum {i in I_feed} X_x2_gh[i]*X_U[2] = 1*X_U[2]; > > s.t. CONS_E_5: sum {i in I_feed} X_x1_km[i]*X_U[3] = 1*X_U[3]; > s.t. CONS_E_6: sum {i in I_feed} X_x2_kl[i]*X_U[3] = 1*X_U[3]; > > s.t. CONS_IE_7: X_U[1] + X_U[2] + X_U[3] >=1; > > Actually, I have three boxes and I want to arbitrarily choose one of them. Is it the right code? > > I expect that if X_U[1] takes 0 then ignore two s.t. [CONS_E_1, CONS_E_2]. > > If I compare with programming languages like C#, If I declare a binary var then in each line it takes a value 0 or 1. Here in AMPL I am not sure about the initialization. > > if a var defined get 0, it remains zero in all lines or changes? If change it's difficult to construct a logical block. 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 [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/ampl. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |