<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='mso-fareast-language:EN-US'>The u and o arrays are variable vectors:<o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'>variables:<o:p></o:p></span></p><p class=MsoNormal style='text-indent:35.4pt'><span lang=EN-GB style='color:#1F497D'>x[sources,destinations]: binary;</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'> </span><span lang=EN-GB style='color:red'>u[sources]:real[0..];</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-GB style='color:red'> o[sources]:real[0..];</span><o:p></o:p></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'>which I use as positive and negative slack variables in the supply constraints:<o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'>constraints:</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'> </span><span lang=EN-GB style='color:red'>supplies {i in sources : sum{j in destinations: d[j]*x[i,j]} +u[i] -o[i] = s[i];}</span><o:p></o:p></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'>To minimise the under and over deliveries these slack variables have to be minimised in the objective function:<o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'>objectives:</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'> </span><span lang=EN-GB style='color:red'>sum{i in sources: u[i]+o[i]} ->min;</span><o:p></o:p></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><a name="_MailEndCompose"><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></a></p><span style='mso-bookmark:_MailEndCompose'></span><p class=MsoNormal><b>Von:</b> James Carlson [<a href="mailto:jddcarlson@gmail.com">mailto:jddcarlson@gmail.com</a>] <br><b>Gesendet:</b> Sonntag, 26. November 2017 15:08<br><b>An:</b> Mike Steglich <<a href="mailto:mike.steglich@berlin.de">mike.steglich@berlin.de</a>><br><b>Betreff:</b> Re: [Cmpl] objective function with a percentage (divisor)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Yes, I have an loss between supply and demand. It is a bit different than a typical lp Model. I really appreciate your help. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>The cmpl is amazing, I am really enjoying working with it - thanks, James.<o:p></o:p></p><p class=MsoNormal>Sent from my iPad<o:p></o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'><br>On Nov 26, 2017, at 8:56 AM, Mike Steglich <<a href="mailto:mike.steglich@berlin.de">mike.steglich@berlin.de</a>> wrote:<o:p></o:p></p><p class=MsoNormal>Hi James,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>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):<o:p></o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Mike<o:p></o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><p class=MsoNormal>Am 25.11.2017 um 21:51 schrieb James Carlson <<a href="mailto:jddcarlson@gmail.com">jddcarlson@gmail.com</a>>:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>hey Mike,<o:p></o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>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!<o:p></o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>James<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>On Sat, Nov 25, 2017 at 10:38 AM, Mike Steglich <<a href="mailto:mike.steglich@berlin.de" target="_blank">mike.steglich@berlin.de</a>> wrote:<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>Hi James,</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>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:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>%data : sources set, destinations set, s[sources], d[destinations], c[sources,destinations] </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>parameters:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> { i in sources , j in destinations: </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> costs[i,j]:= c[i,j]*d[j]; </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> } </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>variables:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> x[sources,destinations]: binary;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><span lang=EN-GB style='color:red'>u[sources]:real[0..];</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:red'> o[sources]:real[0..];</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>objectives:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> #Total_cost: sum{i in sources, j in destinations : #costs[i,j] * x[i,j]} +</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><span lang=EN-GB style='color:red'>sum{i in sources: u[i]+o[i]} ->min;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>constraints:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><span lang=EN-GB style='color:red'>supplies {i in sources : sum{j in destinations: d[j]*x[i,j]} +u[i] -o[i] = s[i]*0.8;}</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:35.4pt'><span lang=EN-GB style='color:#1F497D'>demands {j in destinations : sum{i in sources : x[i,j]} = 1;} </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>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. </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>This absolute differences of the actual quantities to the supplies of the sources are to be minimised in the objective function.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>Cheers,</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN-GB style='color:#1F497D'>Mike</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><a name="m_4196990214122144165__MailEndCompose"><span lang=EN-GB style='color:#1F497D'> </span></a><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b>Von:</b> Cmpl [mailto:<a href="mailto:cmpl-bounces@coin-or.org" target="_blank">cmpl-bounces@coin-or.org</a>] <b>Im Auftrag von </b>James Carlson<br><b>Gesendet:</b> Samstag, 25. November 2017 04:10<br><b>An:</b> <a href="mailto:cmpl@list.coin-or.org" target="_blank">cmpl@list.coin-or.org</a><br><b>Betreff:</b> [Cmpl] objective function with a percentage (divisor)<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:12.0pt'>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:<br>------------------------------------------------------------------------------------------------------------------------------------------<br>%data : sources set, destinations set, s[sources], d[destinations], c[sources,destinations] <br>%display nonZeros<br><br>parameters:<br> { i in sources , j in destinations: costs[i,j]:= c[i,j]*d[j]; } <br> <br>variables:<br> x[sources,destinations]: binary;<br><br>objectives:<br> Total_cost: sum{i in sources, j in destinations : costs[i,j] * x[i,j]} +<br> sum{i in sources : sum{j in destinations: d[j]*x[i,j]} - s[i]} ->min;<br><br>constraints:<br> supplies {i in sources : sum{j in destinations: d[j]*x[i,j]} >= s[i]*0.8;}<br> demands {j in destinations : sum{i in sources : x[i,j]} = 1;} <br>------------------------------------------------------------------------------------------------------------------------------------------<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:12.0pt'>I would like to try something like this for my objectives:<br><br> Total_cost: sum{i in sources, j in destinations : costs[i,j] * x[i,j]} +<br> sum{i in sources : sum{j in destinations: d[j]*x[i,j]} - s[i]}<b>/s[i]</b> ->min;<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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). <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>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.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Any suggestions would be appreciated! thank you. <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><tester-added_Mikes_suggestions.zip><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>