[Cmpl] Piece-Wise Linearization Syntax Question

Mike Steglich mike.steglich at th-wildau.de
Tue Nov 28 14:18:16 EST 2017


Hi Bhrett,

Please find my answers below:


> Am 27.11.2017 um 20:22 schrieb Ogden, Bhrett A. <ogdenba at cdmsmith.com>:
> 
> Hi Mike,
>  
> Thanks for your correction here. I have a few more syntax-related questions from the attached file.
>  
> 1. What does unexpected symbol var mean in the instance below? Normally I find that I’ve used an undefined variable, but I don’t see any issue with that here:
> 
> # Force x_(i+1) = 0 whenever x_i < u_i (pg 574)
> special_condition$1${
> e in export_ports,
> i in import_ports,
> r in route_types,
> s in seasons,
> g in grains,
> n in approximation_intervals:
> { n < len(approximation_intervals) && #Syntax error unexpected SYMBOL_VAR
> x_val_interval[e,i,r,s,g,n] < tonnage_intervals[s,g,n]:
> x_val_interval[e,i,r,s,g,n+1] = 0;
> }
> }

You try to compare the values of two variables (x_val_interval[e,i,r,s,g,n] < tonnage_intervals[s,g,n]), which is not possible within a Cmpl programme, because these values are only available after obtaining the solution by the solver.


> 
> 2. What does “product of variable has too much indexes” error message mean?
>  
> transport_cost$1$ {
> e in export_ports,
> i in import_ports,
> r in route_types,
> s in seasons,
> g in grains: 
> transport_cost[e,i,r,s,g] = sum{
> n in approximation_intervals:
> x_val_interval[e,i,r,s,g,n] * m[e,i,s,g,n] * route_nmiles[e,i,r] * transport_cost_per_mton_nmile #Syntax issue: Product of variable has too much indexes
> };
> }


First of all … you want to multiply two variables: x_val_interval[e,i,r,s,g,n] * m[e,i,s,g,n].  Cmpl is able to transform equivalentely a product of variables into a system of linear inequations, if at least one of the factors is integer. But your variables are continuous variables. 

Cmpl tries also to transform a product of continues variables, but this is not an exact transformation and I cannot recommend it.  

The second issue is that the number of indices are restricted in Cmpl and the reformulation of products of variables leads to generated artificial variables which have in your example more indices as allowed. I could increase the maximum number of indices in the Cmpl source code and could send a new binary if necessary.


>  
> 3. How can I properly format this stamen involving a power? I’m not having any luck with this.
>  
> #Get cost for the tonnage intervals
> solve_fx$1$ {
> e in export_ports,
> i in import_ports,
> s in seasons,
> g in grains,
> n in approximation_intervals:
> fx[e,i,s,g,n] = exp(a[e,i]) * (n*tonnage_intervals[s,g])^b[e,i]; # Syntax issue with power
> }


The expression  (n*tonnage_intervals[s,g])^b[e,i]; is non-linear because you want to calculate the exponentiation of the  variable tonnage_intervals[s,g]. Cmpl only supports linear programmes. 
  
>  
> 4. What is proper format for this statement? I’m having an issue getting the operators and parenthesis in a format that CMPL accepts.
>  
> #Get slope for piece-wise approximation
> solve_m$1$ {
> e in export_ports,
> i in import_ports,
> s in seasons,
> g in grains,
> n in approximation_intervals: 
> {
> n = 1: 
> m[e,i,s,g,n] = fx[e,i,s,g,n] * (1/tonnage_intervals[s,g]); # Arithmetic syntax issue
> | n > 1: 
> m[e,i,s,g,n] = (fx[e,i,s,g,n] - fx[e,i,s,g,n-1])/(n*tonnage_intervals[s,g] - (n-1)*tonnage_intervals[s,g,]); # Arithmetic syntax issue
> }
> }

You cannot divide by a variable in a constraint. You could re-arrange the first constraint into : m[e,i,s,g,n] * tonnage_intervals[s,g] = fx[e,i,s,g,n] ; But this leads to a product of variables ( m[e,i,s,g,n] * tonnage_intervals[s,g]). As mentioned before,  Cmpl is able to transform equivalently a product of variables into a system of linear inequations, if at least one of the factors is integer. But your variables are continuous variables. (fx[export_ports,import_ports,seasons,grains,approximation_intervals]:real[0..]; and m[export_ports,import_ports,seasons,grains,approximation_intervals]:real[0..];) 

This issues also happens for the second constraint in you if clause.

>  
> Thank you for any advice or clarification.
>  
> Best,
>  
> Bhrett Ogden
> Information Management Software Developer
> CDM Smith
> 1050 N Reed Station Rd Suite D
> Carbondale, IL 62902
> T: 312.780.7869
> ogdenba at cdmsmith.com <mailto:ogdenba at cdmsmith.com>
> cdmsmith.com <http://cdmsmith.com/>




Cheers,

Mike

>  
> From: Mike Steglich [mailto:mike.steglich at th-wildau.de <mailto:mike.steglich at th-wildau.de>] 
> Sent: Monday, November 20, 2017 6:24 AM
> To: Ogden, Bhrett A. <ogdenba at cdmsmith.com <mailto:ogdenba at cdmsmith.com>>
> Cc: cmpl at list.coin-or.org <mailto:cmpl at list.coin-or.org>
> Subject: Re: [Cmpl] Piece-Wise Linearization Syntax Question
>  
> Hi Bhrett,
>  
> Hmm I am actually scatty because I forgotten to answer your second question:
>  
> This expression works:
>  
> tonnage_intervals$1$ {
> s in seasons,
> g in grains,
> i in approximation_intervals:
> tonnage_intervals[i,s,g] = worldwide_demand[s,g] * i * 1/len(approximation_intervals); # Division won't work. I'm having to hardcode 0.25 for now.
> }
>  
> if you imbed 1/len(approximation_intervals in brackets:
> tonnage_intervals$1$ {
> s in seasons,
> g in grains,
> i in approximation_intervals:
> tonnage_intervals[i,s,g] = worldwide_demand[s,g] * i * (1/len(approximation_intervals));
> }
>  
> Mike
> 
> 
>  
> 
> Am 15.11.2017 um 20:52 schrieb Ogden, Bhrett A. <ogdenba at cdmsmith.com <mailto:ogdenba at cdmsmith.com>>:
> 
> Thank you for your prompt answer to my last question. 
>  
> I have another question regarding syntax of CMPL. I have a power function that represents a route cost that I would like to linearize. I am using linear approximation to consider the range of options and break the non-linear equation into a four-part piece-wise equation, f(x) ~= f(n) + f’(n)(x-n), where n is the mean route tonnage in the interval. The power function is C = e^a * x^b where a and b are constants that depend on the route origin/destination and x is the route tonnage. One element that I am trying to minimize is the sum of the transport costs. 
>  
> I have approximated the cost to f(x) = e^a * n^b * (1 + b * n^-1 * x – b), where n is the mean route tonnage in the interval and a and b are constants with respect to the route. Assuming that all tonnages lie within the first interval for now (to avoid complicating this question with piece-wise syntax), how can I represent this in CMPL? I was having issues with using parenthesis so I have done all of the distributions. Now I am receiving syntax errors about ^. What is the proper way to represent this?
>  
> transport_cost$1$ {
> e in export_ports,
> i in import_ports,
> s in seasons,
> g in grains,
> r in route_type: 
> transport_cost[e,i,r,s,g] = exp(a[e,i]) * mean_tonnage_for_interval[1,s,g] ^ b[e,i] + b[e,i] * exp(a[e,i]) * route_tonnage[e,i,r,s,g] * mean_tonnage_for_interval[1,s,g] ^ b[e,i] * mean_tonnage_for_interval[1,s,g] ^ -1 - exp(a[e,i])* b * mean_tonnage_for_interval[1,s,g] ^ b[e,i];
> }
>  
> Would you also be able to explain why I get a syntax error if I divide in the following situation?:
>  
> tonnage_intervals$1$ {
> s in seasons,
> g in grains,
> i in approximation_intervals:
> tonnage_intervals[i,s,g] = worldwide_demand[s,g] * i * 1/len(approximation_intervals); # Division won't work. I'm having to hardcode 0.25 for now.
> }
>  
> Thank you for your assistance.
>  
> Best,
> Bhrett Ogden
> _______________________________________________
> Cmpl mailing list
> Cmpl at list.coin-or.org <mailto:Cmpl at list.coin-or.org>
> https://list.coin-or.org/mailman/listinfo/cmpl <https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cmpl&d=DwMFaQ&c=NpiPIT1KNSO0vXgGk6ogJQ&r=lti1h6i9rU5mEC99NvhtD9QtmLoHcyEs5V5LTq78EsM&m=iakxlbWQOSKuVBjy57i_AAXrPmasU7QkeNtxBBAYFNY&s=Xzgr46f-5U3RODSHpP9XNrS1zNErazUh_atWM2K16HM&e=><Seasonal.cmpl><Seasonal.cdat>_______________________________________________
> Cmpl mailing list
> Cmpl at list.coin-or.org <mailto:Cmpl at list.coin-or.org>
> https://list.coin-or.org/mailman/listinfo/cmpl <https://list.coin-or.org/mailman/listinfo/cmpl>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20171128/cd5ca09f/attachment.html>


More information about the Cmpl mailing list