[Cmpl] : Re: objective function with a percentage (divisor)

mike.steglich at th-wildau.de mike.steglich at th-wildau.de
Mon Nov 27 05:00:57 EST 2017


The u and o arrays are variable vectors:

 

variables:

x[sources,destinations]: binary;

             u[sources]:real[0..];

             o[sources]:real[0..];

 

which I use as positive and negative slack variables in the supply
constraints:

 

constraints:

             supplies {i in sources  : sum{j in destinations: d[j]*x[i,j]}
+u[i] -o[i] = s[i];}

 

To minimise the under and over deliveries these slack variables have to  be
minimised in the objective function:

 

objectives:

            sum{i in sources: u[i]+o[i]} ->min;

 

 

 

Von: James Carlson [mailto:jddcarlson at gmail.com] 
Gesendet: Sonntag, 26. November 2017 15:08
An: Mike Steglich <mike.steglich at berlin.de <mailto:mike.steglich at berlin.de>
>
Betreff: Re: [Cmpl] objective function with a percentage (divisor)

 

Yes, I have an loss between supply and demand.  It is a bit different than a
typical lp    Model.  I really appreciate your help.  

 

Do you mind explaining how the u and o arrays are populated?  It appears,
they are either predefined arrays or the constraint definition implicitly
defines them.

 

The cmpl is amazing, I am really enjoying working with it - thanks, James.

Sent from my iPad


On Nov 26, 2017, at 8:56 AM, Mike Steglich <mike.steglich at berlin.de
<mailto:mike.steglich at berlin.de> > wrote:

Hi James,

 

The total demand has to be unequal to the total supply. (You used obviously
the expression s[i]*0.8 in your original model to have unequal demands and
supplies due to the equal demands and supplies in your Excel sheet):

Thanks,

 

Mike

 

Am 25.11.2017 um 21:51 schrieb James Carlson <jddcarlson at gmail.com
<mailto:jddcarlson at gmail.com> >:

 

hey Mike,

Thank you for he prompt reply. As you very accurately stated i am attempting
to minimize the under and over delivery (thank you for the clarification).
I have implemented your suggestions and it runs in the Solver.  It appears
the u and o arrays are zero could you suggest how i should define the U and
O arrays in CMPL so they are non-zero values?  Attached is an updated model
... thank you again for your help!

James

 

On Sat, Nov 25, 2017 at 10:38 AM, Mike Steglich <mike.steglich at berlin.de
<mailto:mike.steglich at berlin.de> > wrote:

Hi James,

If I am right to assume that you want to minimise the under and over
delivery (beside the transportation costs) then I would like to propose the
following model:

 

%data : sources set, destinations set, s[sources], d[destinations],
c[sources,destinations] 

 

parameters:

             { i in sources , j in destinations: 

        costs[i,j]:= c[i,j]*d[j]; 

    }        

             

variables:

             x[sources,destinations]: binary;

             u[sources]:real[0..];

             o[sources]:real[0..];

objectives:

             #Total_cost: sum{i in sources, j in destinations : #costs[i,j]
* x[i,j]} +

             sum{i in sources: u[i]+o[i]} ->min;

 

constraints:

             supplies {i in sources  : sum{j in destinations: d[j]*x[i,j]}
+u[i] -o[i] = s[i]*0.8;}

demands  {j in destinations : sum{i in sources : x[i,j]} =  1;} 

 

There are to new vectors of non-negative, continues variables (u for under
deliveries and o for over deliveries) to be used in the extended supply
constraints. 

 

This absolute differences of the actual quantities to the supplies of the
sources are to be minimised in the objective function.

 

Cheers,

 

Mike

 

Von: Cmpl [mailto:cmpl-bounces at coin-or.org <mailto:cmpl-bounces at coin-or.org>
] Im Auftrag von James Carlson
Gesendet: Samstag, 25. November 2017 04:10
An: cmpl at list.coin-or.org <mailto:cmpl at list.coin-or.org> 
Betreff: [Cmpl] objective function with a percentage (divisor)

 

good evening, I am new to CMPL.  I took several LP and combination
optimization courses in university - in other words I am very new to this!
I have successfully created a model in SolverStudio and the results seem
reasonable.  I am now attempting to change the objective function so the
that difference between the delivered volume versus the demand is a ratio
(or absolute).  Attached is my model:
----------------------------------------------------------------------------
--------------------------------------------------------------
%data : sources set, destinations set, s[sources], d[destinations],
c[sources,destinations] 
%display nonZeros

parameters:
    { i in sources , j in destinations: costs[i,j]:= c[i,j]*d[j]; }    
    
variables:
    x[sources,destinations]: binary;

objectives:
    Total_cost: sum{i in sources, j in destinations : costs[i,j] * x[i,j]} +
                sum{i in sources  : sum{j in destinations: d[j]*x[i,j]} -
s[i]}  ->min;

constraints:
    supplies {i in sources  : sum{j in destinations: d[j]*x[i,j]} >=
s[i]*0.8;}
    demands  {j in destinations : sum{i in sources : x[i,j]} =  1;} 
----------------------------------------------------------------------------
--------------------------------------------------------------

I would like to try something like this for my objectives:

    Total_cost: sum{i in sources, j in destinations : costs[i,j] * x[i,j]} +
                sum{i in sources  : sum{j in destinations: d[j]*x[i,j]} -
s[i]}/s[i]  ->min;

As i mentioned above I am attempting to make the OF minimize the error as a
percentage delivered to each destination.  This is meant to overcome the
problem of an under or over delivery is offset by an equal (negative or
positive) amount so the function is not really minimizing the value (it is
always almost zero due to aggregation of offsetting positive and negative
values).  

 

Attached is an OpenSolver excel model (in a zip file).  Please note I have
made all the costs equal to 1 to better diagnose the OF's second term.

 

Any suggestions would be appreciated!  thank you. 

 

 

<tester-added_Mikes_suggestions.zip>

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20171127/92424071/attachment.html>


More information about the Cmpl mailing list