$call test input.xls -nt input.gdx && gdxls -propertyfile properties.txt
This will cause that gdxls will only be called if input.xls has been changed since the last time this conversion was performed.
I am a full-time consultant and provide services related to the design, implementation and deployment of mathematical programming, optimization and data-science applications. I also teach courses and workshops. Usually I cannot blog about projects I am doing, but there are many technical notes I'd like to share. Not in the least so I have an easy way to search and find them again myself. You can reach me at erwin@amsterdamoptimization.com.
C:\Program Files\GAMS22.7>gams x r=x
--- Job x Start 10/30/08 16:56:41
*** Workfile synchronization problem in section BAS-END
*** Generated under GAMS Ver = WEX228-228
*** Processed under GAMS Ver = WEX227-227
*** Status: Terminated due to systems error in WF Section error: Expected = BAS-END, Found =
*** Inspect listing file for more information
***
*** GAMS Base Module May 1, 2008 22.7.2 WEX 4648.4799 WEI x86_64/MS Windows
***
*** GAMS Development Corporation
*** 1217 Potomac Street, NW
*** Washington, DC 20007, USA
*** 202-342-0180, 202-342-0181 fax
*** support@gams.com, www.gams.com
***
*** opentext W=0 FN="225a\gamsnext.cmd"
--- Job x.gms Stop 10/30/08 16:56:41 elapsed 0:00:00.020
***
*** Gams Exit Msg = WF Section error: Expected = BAS-END, Found =
***
C:\Program Files\GAMS22.7>
cost1 .. z =e= sum((i,j,k), x(i,j,k)*log(x(i,j,k)+e)) -
sum((i,j,k), x(i,j,k)*log(c(i,j)+e));
Total CPU secs in IPOPT (w/o function evaluations) = 6.033
Total CPU secs in NLP function evaluations = 33.971
cost2 .. z =e= sum((i,j,k), x(i,j,k)*log((x(i,j,k)+e)/(c(i,j)+e)));
Total CPU secs in IPOPT (w/o function evaluations) = 5.905
Total CPU secs in NLP function evaluations = 0.541
The real model is much larger (> half a million variables), and then this difference becomes really significant. One version can solve the model quickly to near optimality (with Mosek) and the other version is not able to finish in reasonable time.
$onecho > trnsport2.properties
o=trnsport2.xls
i=trnsport2.gdx
parameter=c
rng=a1
rdim=1
cdim=1
parameter.2=c
rng.2=f1
rdim.2=2
cdim.2=0
parameter.3=c
rng.3=sheet1!A10
rdim.3=0
cdim.3=2
$offecho
$call gamslib trnsport
$call gams trnsport lo=2 gdx=trnsport2
$call ./gdxls -propertyfile trnsport2.properties
$call oocalc trnsport2.xls
$onecho > trnsport.properties
i=trnsport.xls
o=trnsport.gdx
parameter=c
rng=b4
rdim=1
cdim=1
$offecho
$call gdxls -propertyfile trnsport.properties
sets
i 'canning plants' / seattle, san-diego /
j 'markets' / new-york, chicago, topeka /
;
parameter c(i,j);
$gdxin trnsport.gdx
$load c
display c;
erwin@erwin-desktop:~/workspace/gdxls$ gams test1.gms
--- Job test1.gms Start 10/25/08 09:42:14
GAMS Rev 228 Copyright (C) 1987-2008 GAMS Development. All rights reserved
Licensee: GAMS Development Corporation, Washington, DC G871201/0000CA-ANY
Free Demo, 202-342-0180, sales@gams.com, www.gams.com DC0000
--- Starting compilation
--- test1.gms(12) 2 Mb
--- call gdxls -propertyfile trnsport.properties
GDXLS V 0.1, Amsterdam Optimization (c) 2008
xls2gdx,input=trnsport.xls,output=trnsport.gdx
Parameter;name=c;range=B4:E6;rdim=1;cdim=1
xls2gdx done
--- test1.gms(20) 3 Mb
--- GDXin=/home/erwin/workspace/gdxls/trnsport.gdx
--- test1.gms(23) 3 Mb
--- Starting execution: elapsed 0:00:00.186
--- test1.gms(23) 4 Mb
*** Status: Normal completion
--- Job test1.gms Stop 10/25/08 09:42:14 elapsed 0:00:00.188
erwin@erwin-desktop:~/workspace/gdxls$
---- 23 PARAMETER c gdxls range:B4:E6
new-york chicago topeka
seattle 2.500 1.700 1.800
san-diego 2.500 1.800 1.400
$ontext
Magic Squares
Take consecutive numbers from 1 to n^2 and
arrange them in a n x n array such that
every row, every column and the two diagonals
all add up to the same total.
See also: http://forum.swarthmore.edu/alejandre/magic.square.html
Erwin Kalvelagen, nov 1999
$offtext
set k "board size" /k1*k5/;
alias (k,kk);
set i "numbering of cells" /i1*i25/;
alias(i,j);
abort$(sqr(card(k)) <> card(i)) "card(i) should be card(k)^k";
$ontext
cells are numbered:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
$offtext
variable x(i) "value of board cell i";
binary variable y(i,j) "permutation matrix";
variable s "sum";
parameter p(i);
p(i)=ord(i);
equations
unique(i) "make sure each x(i) is unique"
yrow(i) "row sum of y"
ycol(j) "col sum of y"
row(k) "row of board"
col(k) "col of board"
diag1 "first diagonal"
diag2 "second diagonal"
;
set map(k,kk,i);
scalar cnt /0/;
loop((k,kk),
cnt = cnt + 1;
map(k,kk,i)$(ord(i)=cnt)=yes;
);
display map;
set revdiag(i);
loop(map(k,kk,i)$((ord(k)+ord(kk))=card(k)+1),
revdiag(i) = yes;
);
display revdiag;
unique(i)..x(i)=e=sum(j,y(i,j)*p(j));
yrow(i).. sum(j,y(i,j))=e=1;
ycol(j).. sum(i,y(i,j))=e=1;
row(k).. sum(map(k,kk,i), x(i)) =e= s;
col(k).. sum(map(kk,k,i), x(i)) =e= s;
diag1.. sum(map(k,k,i), x(i)) =e= s;
diag2.. sum(revdiag, x(revdiag)) =e= s;
equations
extra1 "extra constraint for performance"
extra2 "another redundant constraint for performance"
;
* additional constraints below
scalar n "size of set i";
n = card(i);
extra1.. sum(i,x(i)) =e= n*(n+1)/2;
extra2.. sum((i,j),y(i,j)) =e= n;
* fix s with its known value
scalar magicsum;
magicsum = card(k)*(n+1)/2;
s.fx = magicsum;
model m1 /all/;
solve m1 using mip minimizing s;
display x.l;
parameter board(k,kk);
board(k,kk) = sum(map(k,kk,i), x.l(i));
display board;
$ontext
Magic Squares
Take consecutive numbers from 1 to n^2 and
arrange them in a n x n array such that
every row, every column and the two diagonals
all add up to the same total.
See also: http://forum.swarthmore.edu/alejandre/magic.square.html
Erwin Kalvelagen, nov 1999
$offtext
set k "board size" /k1*k5/;
alias (k,kk);
set i "numbering of cells" /i1*i25/;
alias(i,j);
abort$(sqr(card(k)) <> card(i)) "card(i) should be card(k)^k";
$ontext
cells are numbered:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
$offtext
variable x(i) "value of board cell i";
binary variable y(i,j) "permutation matrix";
variable s "sum";
parameter p(i);
p(i)=ord(i);
equations
unique(i) "make sure each x(i) is unique"
yrow(i) "row sum of y"
ycol(j) "col sum of y"
row(k) "row of board"
col(k) "col of board"
diag1 "first diagonal"
diag2 "second diagonal"
;
set map(k,kk,i);
scalar cnt /0/;
loop((k,kk),
cnt = cnt + 1;
map(k,kk,i)$(ord(i)=cnt)=yes;
);
display map;
set revdiag(i);
loop(map(k,kk,i)$((ord(k)+ord(kk))=card(k)+1),
revdiag(i) = yes;
);
display revdiag;
unique(i)..x(i)=e=sum(j,y(i,j)*p(j));
yrow(i).. sum(j,y(i,j))=e=1;
ycol(j).. sum(i,y(i,j))=e=1;
row(k).. sum(map(k,kk,i), x(i)) =e= s;
col(k).. sum(map(kk,k,i), x(i)) =e= s;
diag1.. sum(map(k,k,i), x(i)) =e= s;
diag2.. sum(revdiag, x(revdiag)) =e= s;
equations
extra1 "extra constraint for performance"
extra2 "another redundant constraint for performance"
;
* additional constraints below
scalar n "size of set i";
n = card(i);
extra1.. sum(i,x(i)) =e= n*(n+1)/2;
extra2.. sum((i,j),y(i,j)) =e= n;
* fix s with its known value
scalar magicsum;
magicsum = card(k)*(n+1)/2;
s.fx = magicsum;
model m1 /all/;
solve m1 using mip minimizing s;
display x.l;
parameter board(k,kk);
board(k,kk) = sum(map(k,kk,i), x.l(i));
display board;
---- 60 SET map
i1 i2 i3 i4 i5 i6 i7 i8 i9
k1.k1 YES
k1.k2 YES
k1.k3 YES
k1.k4 YES
k1.k5 YES
k2.k1 YES
k2.k2 YES
k2.k3 YES
k2.k4 YES
+ i10 i11 i12 i13 i14 i15 i16 i17 i18
k2.k5 YES
k3.k1 YES
k3.k2 YES
k3.k3 YES
k3.k4 YES
k3.k5 YES
k4.k1 YES
k4.k2 YES
k4.k3 YES
+ i19 i20 i21 i22 i23 i24 i25
k4.k4 YES
k4.k5 YES
k5.k1 YES
k5.k2 YES
k5.k3 YES
k5.k4 YES
k5.k5 YES
---- 99 VARIABLE x.L value of board cell i
i1 6.000, i2 22.000, i3 7.000, i4 13.000, i5 17.000, i6 20.000, i7 24.000, i8 2.000
i9 18.000, i10 1.000, i11 19.000, i12 12.000, i13 16.000, i14 8.000, i15 10.000, i16 9.000
i17 3.000, i18 25.000, i19 5.000, i20 23.000, i21 11.000, i22 4.000, i23 15.000, i24 21.000
i25 14.000
---- 103 PARAMETER board
k1 k2 k3 k4 k5
k1 6.000 22.000 7.000 13.000 17.000
k2 20.000 24.000 2.000 18.000 1.000
k3 19.000 12.000 16.000 8.000 10.000
k4 9.000 3.000 25.000 5.000 23.000
k5 11.000 4.000 15.000 21.000 14.000
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
30 4.2974620e+002 3.78e+001 3.39e+001 -1.9 5.15e+002 - 8.47e-002 1.96e-001f 1
31 4.2874611e+002 2.87e+001 2.01e+002 -1.9 5.03e+002 - 1.02e-001 2.40e-001f 1
32 4.2792912e+002 2.28e+001 1.65e+002 -2.0 4.90e+002 - 2.02e-001 2.07e-001f 1
S O L V E S U M M A R Y
MODEL LANDentSN2 OBJECTIVE ENTROPY
TYPE NLP DIRECTION MINIMIZE
SOLVER MOSEK FROM LINE 249734
**** SOLVER STATUS 4 TERMINATED BY SOLVER
**** MODEL STATUS 7 INTERMEDIATE NONOPTIMAL
**** OBJECTIVE VALUE 217.6762
RESOURCE USAGE, LIMIT 539.256 900000.000
ITERATION COUNT, LIMIT 0 900000
EVALUATION ERRORS 0 0
MOSEK Link Aug 1, 2008 22.8.1 WEX 5438.6015 WEI x86_64/MS Windows
M O S E K version 5.0.0.90 (Build date: Jun 6 2008 14:57:22)
Copyright (C) MOSEK ApS, Fruebjergvej 3, Box 16
DK-2100 Copenhagen, Denmark
http://www.mosek.com