[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[3]: [Help-glpk] slow matrix generation compared to AMPL
From: |
Andrew Makhorin |
Subject: |
Re[3]: [Help-glpk] slow matrix generation compared to AMPL |
Date: |
Tue, 10 Aug 2004 15:57:33 +0400 |
Here is an example of inefficient coding in MathProg.
Let there be the following constraint declaration:
s.t. CAP{i in I, j in J: A[i,j] > 0 and (i,j) in S} ... ;
An equivalent pseudo-code used by the MathProg translator to generate
CAP is the following:
for {i in I}
for {j in J}
if A[i,j] > 0 and (i,j) in S then generate CAP[i,j];
where 'if' is executed for *all* doublets (i,j) in I x J.
It is understood that if set S contain much less doublets than I x J,
the following declaration would be much more efficient:
s.t. CAP{(i,j) in S: A[i,j] > 0} ... ;
because its pseudo-code is the following:
for {(i,j) in S}
if A[i,j] > 0 then generate CAP[i,j];
where 'if' is executed only for doublets (i,j) in S, and, moreover,
there is no need to test whether (i,j) belongs to S or not.
Note that (unlike the AMPL system) the MathProg translator always
executes all constructions in the order they are written in the model
description.
Andrew Makhorin