Dear all,
I try to modify a parameter of a ModelInstance representing and MCP model. A minimal example based on the MCP transport model from the library is given below. Instantiating the model, an error is raised from “gmoLoadDataLegacy” telling me that I have an unmatched column and no unmatched row (which reminds me on the unmatched variable/equation error of MCP models).
*** gmoLoadDataLegacy: fillMatches failed: matching error: nUnmatchedCols = 1 but nUnmatchedRows = 0
*** Could not load data from file: matching error: nUnmatchedCols = 1 but nUnmatchedRows = 0
Against the background, that the documentation states, that modifiers are converted to variables in the ModelInstance, I have two questions:
(1) Is it possible to manipulate MCP models using ModelInstances?
(2) If yes, can you provide me a hint what is going wrong with the code below?
Best regards
Jan
P.S. Versions: Python 2.7, Windows 7, GAMS 24.8.3
# coding: utf-8
import gams
model_text = """$Title Transportation model as equilibrium problem (TRANSMCP,SEQ=126)
$Ontext
Dantzig's original transportation model (TRNSPORT) is
reformulated as a linear complementarity problem. We first
solve the model with fixed demand and supply quantities, and
then we incorporate price-responsiveness on both sides of the
market.
Dantzig, G B, Chapter 3.3. In Linear Programming and Extensions.
Princeton University Press, Princeton, New Jersey, 1963.
$Offtext
Sets
i canning plants / seattle, san-diego /
j markets / new-york, chicago, topeka / ;
Parameters
a(i) capacity of plant i in cases (when prices are unity)
/ seattle 350
san-diego 600 /,
b(j) demand at market j in cases (when prices equal unity)
/ new-york 325
chicago 300
topeka 275 /,
esub(j) price elasticity of demand (at prices equal to unity)
/ new-york 1.5
chicago 1.2
topeka 2.0 /
* ADDED DEMAND MULTIPLIER
multdem demand mulitplier /1/
;
Table d(i,j) distance in thousands of miles
new-york chicago topeka
seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4 ;
Scalar f freight in dollars per case per thousand miles /90/ ;
Parameter c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
Parameter pbar(j) reference price at demand node j;
Positive variables
w(i) shadow price at supply node i,
p(j) shadow price at demand node j,
x(i,j) shipment quantities in cases;
Equations
supply(i) supply limit at plant i,
fxdemand(j) fixed demand at market j,
prdemand(j) price-responsive demand at market j,
profit(i,j) zero profit conditions;
profit(i,j).. w(i) + c(i,j) =g= p(j);
supply(i).. a(i) =g= sum(j, x(i,j));
* ADDED DEMAND MULTIPLIER
fxdemand(j).. sum(i, x(i,j)) =g= b(j)*multdem;
prdemand(j).. sum(i, x(i,j)) =g= b(j) * (pbar(j)/p(j))**esub(j);
* declare models including specification of equation-variable
* association:
Model fixedqty / profit.x, supply.w, fxdemand.p/ ;
Model equilqty / profit.x, supply.w, prdemand.p/ """
# initialize workspace, options, and checkpoint
ws = gams.GamsWorkspace(debug=2)
opt = ws.add_options()
opt.mcp = "PATH"
cp = ws.add_checkpoint()
# create checkpoint running GAMS file
j_modeltext = ws.add_job_from_string(model_text)
j_modeltext.run(checkpoint=cp)
# intitialize GAMSModelInstance
mi = cp.add_modelinstance()
# add changing parameter to sync_db
multdem = mi.sync_db.add_parameter("multdem", 0, "uniform demand multiplier")
# instantiate the GAMSModelInstance and pass a model definition and GAMSModifier to declare bmult mutable
mi.instantiate("fixedqty using MCP", gams.GamsModifier(multdem), opt)