help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-glpk] How to code restriction on number of variables > 0


From: Baake, Wouter
Subject: Re: [Help-glpk] How to code restriction on number of variables > 0
Date: Thu, 20 Feb 2014 14:48:24 +0000

Hi Heinrich,

Thanks for the help, this does indeed work for me. Unfortunately the resulting 
MIP problem is a bit too complicated (approx. 6000 integer variables) to be 
solved efficiently or at all.
Maybe I'll have to resort to outputting an .lp file and using another solver 
(eg. the CBC solver) to solve the problem.

Regards,
Wouter

-----Original Message-----
From: Heinrich Schuchardt [mailto:address@hidden
Sent: Thursday, February 20, 2014 2:47 PM
To: Baake, Wouter
Cc: 'address@hidden'
Subject: Aw: RE: [Help-glpk] How to code restriction on number of variables > 0

Hello Wouter,

I was thinking of something like:

param max_ingredients := 5; # maximum number of ingredients per product/element 
param M := 1; # maximum value for concentrations var concentration {Product, 
Ingredients, Elements}, >= 0; var x{Product, Ingredients, Elements}, binary; 
s.t. c1{p in Products, e in Elements} :
  sum{i in Ingredients} x[p,i,e] <= max_ingredients; s.t. c2{p in Products, i 
in Ingredients, e in Elements} :
  concentration[p,i,e] <= M * x[p,i,e];

Best regards

Heinrich Schuchardt

http://www.xypron.de


> Gesendet: Donnerstag, 20. Februar 2014 um 14:05 Uhr
> Von: "Baake, Wouter" <address@hidden>
> An: "Heinrich Schuchardt" <address@hidden>
> Cc: "'address@hidden'" <address@hidden>
> Betreff: RE: [Help-glpk] How to code restriction on number of
> variables > 0
>
> Hi Heinrich,
>
> Thanks for your answer, but I'm having some trouble implementing it.
>
> My original model would look something like this:
> set Products;
> set Unit_operations;
> set Ingredients;
> set Elements;
>
> param cost {Products};
> param aim {Products};
> param concentration {Ingredients,Elements};
>
> var ingredient_used {Products, Unit_operations,Ingredients} >= 0;
>
> minimize total_cost: sum{p in Products,u in Unit_operations, i in
> Ingredients}  cost[i] * ingredient_used [p,u,i]; Subject to {p in
> Products, e in Elements}: sum {u in Unit_operations, i in Ingredients}
> (ingredient_used [p,u,i]*concentration[i,e]) = aim[p,e];
>
> To add the binary variable, I would then write this as:
> set Products;
> set Unit_operations;
> set Ingredients;
> set Elements;
>
> param cost {Products};
> param aim {Products};
> param concentration {Ingredients,Elements};
>
> var ingredient_used {Products, Unit_operations,Ingredients} >= 0; var
> ingredient_used_yes_no {Products, Unit_operations,Ingredients} binary;
>
> minimize total_cost: sum{p in Products,u in Unit_operations, i in
> Ingredients}  cost[i] * ingredient_used [p,u,i];
>
> Subject to {p in Products, e in Elements}: sum {u in Unit_operations,
> i in Ingredients} (ingredient_used [p,u,i]*concentration[i,e]) =
> aim[p,e]; Subject to {p in Products,u in Unit_operations,i in
> Ingredients :  ingredient_used_yes_no[p,u,i]=0}:
> ingredient_used[p,u,i]=0;
>
>
> Unfortunately, I then get an error: "operand preceding = has invalid type" 
> which I do not understand.
> You write "Add a constraint limiting the ingredient quantity to zero if the 
> binary is" but my attempts to do this result in errors when I run glpsol. Do 
> you have an example of how to write this constraint?
>
> Regards,
> Wouter
>
>
> -----Original Message-----
> From: Heinrich Schuchardt [mailto:address@hidden
> Sent: Thursday, February 20, 2014 12:37 PM
> To: Baake, Wouter
> Cc: Help Glpk
> Subject: Re: [Help-glpk] How to code restriction on number of
> variables > 0
>
> Hello Wouter,
>
> you can add a binary variable per ingredient.
>
> Add a constraint limiting the ingredient quantity to zero if the binary is 0.
>
> aim <= M *x;
>
> Choose M as small as possible.
>
> Add a constraint for the sum of the binaries.
>
> Best regards
>
> Heinrich Schuchardt
>
> http://www.xypron.de
>
>
> On 20.02.14 at 11:49, Baake, Wouter wrote:
>
> > Hi,
> >
> >
> >
> > I'm modelling a problem where I need to make several products with 
> > different specifications. Each product undergoes several unit operations 
> > where ingredients are added.
> >
> > var ingredient_used {Products, Unit_operations,Ingredients} >= 0;
> >
> >
> >
> > Each ingredient has a cost and the total cost is to be minimized:
> >
> > minimize total_cost: sum{p in Products,u in Unit_operations, i in
> > Ingredients}  cost[i] * ingredient_used [p,u,i];
> >
> >
> >
> > Each ingredient consists of several elements in different concentrations. 
> > Each of the products has an aim value for concentration of each of the 
> > elements in the product:
> >
> > Subject to {p in Products, e in Elements}: sum {u in
> > Unit_operations, i in Ingredients} (ingredient_used
> > [p,u,i]*concentration[i,e]) = aim[p,e];
> >
> >
> >
> > This problem I can model and solve, but I need to add some more constraints.
> >
> > One constraint is that there is a maximum number of ingredients that can be 
> > kept in stock at a given unit operation. As an example, at the first unit 
> > operation, I cannot keep more than 10 ingredients in stock, but the amount 
> > per ingredient is unlimited.
> >
> >
> >
> > How could I translate this into a mathprog constraint?
> >
> >
> >
> > Regards,
> >
> > Wouter
> >
> >
> >
> >
> >
> > ********************************************************************
> > **
> >
> >
> >
> > This transmission is confidential and must not be used or disclosed by 
> > anyone other than the intended recipient. Neither Tata Steel Europe Limited 
> > nor any of its subsidiaries can accept any responsibility for any use or 
> > misuse of the transmission by anyone.
> >
> >
> >
> > For address and company registration details of certain entities
> > within the Tata Steel Europe group of companies, please visit
> > http://www.tatasteeleurope.com/entities
> >
> >
> >
> > ********************************************************************
> > **
> >
> > _______________________________________________
> >
> > Help-glpk mailing list
> >
> > address@hidden
> >
> > https://lists.gnu.org/mailman/listinfo/help-glpk
>
> **********************************************************************
>
> This transmission is confidential and must not be used or disclosed by anyone 
> other than the intended recipient. Neither Tata Steel Europe Limited nor any 
> of its subsidiaries can accept any responsibility for any use or misuse of 
> the transmission by anyone.
>
> For address and company registration details of certain entities
> within the Tata Steel Europe group of companies, please visit
> http://www.tatasteeleurope.com/entities
>
> **********************************************************************
>

**********************************************************************

This transmission is confidential and must not be used or disclosed by anyone 
other than the intended recipient. Neither Tata Steel Europe Limited nor any of 
its subsidiaries can accept any responsibility for any use or misuse of the 
transmission by anyone.

For address and company registration details of certain entities within the 
Tata Steel Europe group of companies, please visit 
http://www.tatasteeleurope.com/entities

**********************************************************************

reply via email to

[Prev in Thread] Current Thread [Next in Thread]