help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Conversion of AMPL model defect #1


From: Andrew Makhorin
Subject: Re: [Help-glpk] Conversion of AMPL model defect #1
Date: Tue, 07 Aug 2012 15:05:11 +0400

> I am presently working on converting a large AMPL/CPLEX model so I can
> learn how the model works and also to compare the execution times with
> CPLEX. I have managed to fix most of the obvious problems but I have a
> couple of issues that I need to ask for help from the GLPK experts.
> 
> The first one is a syntactical one:
> 
> Here is the AMPL code:
> 
> var BP >= 0;
> BP  = sum {t in DAYS, Cid in BANKING_CONTRACTS} (DBQ[t,Cid] +
> DWQ[t,Cid]) * 0.0001 
> 
> This code fails with "BP multiply declared" error.
> 
> I thought it may have been an AMPL defined variable but I have tried a
> number of different formulations using the WikiBook as a guide but
> havent had any success.
> 
> Any ideas?
> 

In constraint statements the 's.t.' keyword may be omitted, so the
second statement is recognized as a constraint whose name is 'BP' (that
statement is syntactically incorrect, because a colon should follow a
constraint name). To fix the error you need to declare 'BP' as a
parameter rather than a variable:

param BP >= 0, := sum {t in DAYS, Cid in BANKING_CONTRACTS} 
(DBQ[t,Cid] + DWQ[t,Cid]) * 0.0001 ;


> This is a model data error and the AMPL code looks reasonable but I
> keep
> getting an empty result set.
> 
> Here is the AMPL code:
> 
>   param effective_MDQ {t in DAYS, Cid in SUPPLY_CONTRACTS} =
>     max {(p,Cid) in DAILY_CONTRACT_PARAMETERS : P2[p] = 1}
>     daily_contract_data[t,Cid,p];  
> 
> I have cut the original problem down to the essentials in the GLPK
> script below but it is still reasonably complex. The parameter
> "effective_MDQ" is meant to be calculated as the maximum of the
> selected
> parameters for each day and each contract but returns empty content.
> 
> The print statement:
> 
>   printf {t in DAYS, (p, Cid) in {(p,Cid) in
> DAILY_CONTRACT_PARAMETERS :
>   P2[p] = 1}}
>     "%d %s %s %4d\n", t, Cid, p, daily_contract_data[t,Cid,p];
> 
> does print out the expected result in the script, but the max()
> function
> in the calculation of the "effective_MDQ" parameter doesnt seem to
> calculate the maximum and I cant work out how to write the statement
> to
> see what elements are being considered for the max() function.
> 
> The test script prints out the important variables and the final value
> of the "effective_MDQ" parameter that is empty.
> 

If the declaration

param foo = ...

the expression that follows '=' is a condition, which the parameter
value should satisfy to. If you want to assign a value to a parameter,
you need to use ':=' rather than '=', i.e.

  param effective_MDQ {t in DAYS, Cid in SUPPLY_CONTRACTS} :=
     max {(p,Cid) in DAILY_CONTRACT_PARAMETERS : P2[p] = 1}
     daily_contract_data[t,Cid,p];  






reply via email to

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