Tuesday, June 10, 2008

GAMS bug: interrupt does not work

The model below does not terminate. One would expect the Interrupt button would allow you to stop the GAMS run. Unfortunately that does not work. Only the Stop button works but that stops the process very abruptly leaving an unfinished listing file.

scalar s /1/;

while(1,
s = s + 1;
s = s - 1;
);

GAMS Feature Request

For the Least Squares solvers:

we currently add a dummy objective to an overdetermined system of linear/non-linear equations. It would be nice if GAMS has a model type say LINSYS and NLSYS that allows to express such a system of equations. There is CNS, but that requires a square system of equations.

How to interrupt GAMS from VBA

> how can I interrupt GAMS cleanly from VBA (I call GAMS
> from VBA using CreateProcess).

You need to send a Ctrl-C to the GAMS child-process. It turns out that stuffing Ctrl-C in the keyboard buffer is unreliable. The easiest is to use a small DLL available from me that can be called as follows:

Private Declare Function GamsInterrupt Lib "gamsinterrupt.dll" _  
(ByVal pid As Long, ByVal InterruptType As Long) As Long
'----------------------------------------------------
Private Sub SendInterrupt(InterruptType As Long)
Dim rc As Long
Dim pid As Long
pid = getpid()
rc = GamsInterrupt(ByVal pid, ByVal InterruptType)
End Sub
'----------------------------------------------------
Private Sub InterruptButton_Click()
' try to interrupt
Call SendInterrupt(0)
End Sub
'----------------------------------------------------
Private Sub KillButton_Click()
' try to kill
Call SendInterrupt(1)
End Sub


The subroutine InterruptButton_Click() mimics the Interrupt button in the GAMS/IDE and KillButton_Click() works like the Stop button. The DLL performas the low-level code-injection and remote thread managament. See also
http://www.amsterdamoptimization.com/packaging.html

Monday, June 9, 2008

A puzzling question

http://groups.google.com/group/sci.op-research/browse_thread/thread/e69aceb123a21ea5

I was a little bit too quick in responding (i.e. before I knew what the problem was). I think he wants to model

x+y=1
x,y binary


linearly but without integer variables. One can get rid of one binary variable:

y = 1-x
x binary

but if we were to be able to get rid of the integer restriction on x also, we would not need MIP solvers anymore.

A variant of the social golfer problem

http://groups.google.com/group/sci.op-research/browse_thread/thread/c45387ea26c8bf6c

> I have 28 golfers playing over four days in foursomes. I want the best
> combination. I realize not everyone can play together. Anyone with
> help? Thanks

See also the social golfer problem http://www.cs.brown.edu/~sello/golf.html.The difficult problem mentioned there has been solved using somealternative mathematical method (I forgot the details).

Analog to this problem we can minimize the number of times player A can meet player B. If this becomes 1 no player meet another player more than once.

I formulated this quickly in GAMS:


$ontext

I have 28 golfers playing over four days in foursomes. I want the best
combination. I realize not everyone can play together. Anyone with
help? Thanks


References:
- problem 10 in CSPLIB (www.csplib.org)
- Barbara Smith, "Reducing Symmetry in a Combinatorial
Design Problem", Tech. Report, School of Computing and
Mathematics, University of Huddersfield, 2001.


$offtext


set
t 'days' /day1*day4/
i 'golfers' /golfer1*golfer28/
g 'group' /group1*group7/
;

alias(i,j);

binary variables x(i,g,t) 'schedule';
positive variable meet(i,j,g,t) 'golfer i and j meet';
free variables maxmeet 'max number of times players meet';

equations
game(i,t) 'each golver plays one game per week'
fourplayer(g,t) 'four players per game'
multiply1(i,j,g,t) 'linearization of multiplication (not used)'
multiply2(i,j,g,t) 'linearization of multiplication (not used)'
multiply3(i,j,g,t) 'linearization of multiplication'
meetcount(i,j)
;

set ij(i,j);
ij(i,j)$(ord(i)>ord(j)) = yes;


*
* golfer plays one game per week
*
game(i,t).. sum(g, x(i,g,t)) =e= 1;

*
* four players per game
*
fourplayer(g,t).. sum(i, x(i,g,t)) =e= 4;

*
* linearization of x(i,g,t)*x(j,g,t)
* Note: we can relax the first two equations multiply1, multiply2
*
multiply1(ij(i,j),g,t).. meet(ij,g,t) =l= x(i,g,t);
multiply2(ij(i,j),g,t).. meet(ij,g,t) =l= x(j,g,t);
multiply3(ij(i,j),g,t).. meet(ij,g,t) =g= x(i,g,t)+x(j,g,t)-1;

meet.lo(ij,g,t) = 0;
meet.up(ij,g,t) = 1;

*
* players i and j can meet only once
*
meetcount(ij(i,j)).. sum((g,t), meet(ij,g,t)) =l= maxmeet;



*
* fix first round
*
set first(i,g) /
(golfer1*golfer4).group1
(golfer5*golfer8).group2
(golfer9*golfer12).group3
(golfer13*golfer16).group4
(golfer17*golfer20).group5
(golfer21*golfer24).group6
(golfer25*golfer28).group7
/;
x.fx(first,'day1') = 1;

model m /game,fourplayer,multiply3,meetcount/;
solve m minimizing maxmeet using mip;

* check
parameter meetcount2(i,j) "sanity check";
meetcount2(i,j)$(not sameas(i,j)) = round(sum((g,t),x.l(i,g,t)*x.l(j,g,t)));
option meetcount2:0:1:1;
display meetcount2;

options x:0:2:1;
display x.l;




This gave a solution within 11 seconds using Cplex:


              S O L V E      S U M M A R Y

MODEL m OBJECTIVE maxmeet
TYPE MIP DIRECTION MINIMIZE
SOLVER CPLEX FROM LINE 87

**** SOLVER STATUS 1 NORMAL COMPLETION
**** MODEL STATUS 1 OPTIMAL
**** OBJECTIVE VALUE 1.0000

RESOURCE USAGE, LIMIT 10.924 1000.000
ITERATION COUNT, LIMIT 28252 10000


with the following schedule:

----     96 VARIABLE x.L  schedule

day1 day2 day3 day4

golfer1 .group1 1 1
golfer1 .group5 1 1
golfer2 .group1 1 1
golfer2 .group3 1
golfer2 .group5 1
golfer3 .group1 1
golfer3 .group2 1
golfer3 .group4 1
golfer3 .group7 1
golfer4 .group1 1
golfer4 .group4 1
golfer4 .group6 1
golfer4 .group7 1
golfer5 .group2 1
golfer5 .group5 1
golfer5 .group7 1 1
golfer6 .group1 1
golfer6 .group2 1 1 1
golfer7 .group1 1
golfer7 .group2 1
golfer7 .group3 1
golfer7 .group6 1
golfer8 .group2 1
golfer8 .group4 1 1
golfer8 .group7 1
golfer9 .group3 1 1
golfer9 .group4 1
golfer9 .group7 1
golfer10.group1 1
golfer10.group2 1
golfer10.group3 1
golfer10.group7 1
golfer11.group3 1 1
golfer11.group6 1
golfer11.group7 1
golfer12.group3 1 1
golfer12.group4 1 1
golfer13.group4 1
golfer13.group6 1 1 1
golfer14.group3 1 1
golfer14.group4 1
golfer14.group7 1
golfer15.group1 1 1
golfer15.group4 1 1
golfer16.group2 1
golfer16.group4 1
golfer16.group5 1 1
golfer17.group3 1
golfer17.group4 1
golfer17.group5 1 1
golfer18.group1 1
golfer18.group3 1
golfer18.group5 1
golfer18.group6 1
golfer19.group2 1
golfer19.group4 1
golfer19.group5 1
golfer19.group6 1
golfer20.group2 1
golfer20.group5 1 1
golfer20.group7 1
golfer21.group2 1
golfer21.group3 1 1
golfer21.group6 1
golfer22.group2 1 1
golfer22.group6 1 1
golfer23.group1 1 1
golfer23.group4 1
golfer23.group6 1
golfer24.group4 1
golfer24.group5 1 1
golfer24.group6 1
golfer25.group3 1
golfer25.group5 1
golfer25.group6 1
golfer25.group7 1
golfer26.group1 1
golfer26.group5 1
golfer26.group6 1
golfer26.group7 1
golfer27.group1 1
golfer27.group7 1 1 1
golfer28.group2 1 1
golfer28.group6 1
golfer28.group7 1

GAMS/Cplex docs headers are messed up

The GAMS/Cplex docs contain some section headers that are messed up. (Actually with LaTeX this usually works correctly; you really have to mess up the input to achieve this).


I don't think any important information is missing.

Modeling question

http://tech.groups.yahoo.com/group/lp_solve/message/10534.

Looks to me using some homotopy method for this is inappropriate (I thought these were for nonlinear problems instead of discrete problems).

GAMS/IDE suggestion

It would be helpful if the edit boxes in the Find/Replace window would be larger if the window is enlarged. Long paths are not completely visible using the default sizes for the edit boxes. Click on the picture to see what I mean. The edit boxes should/could scale with the window size.

Friday, June 6, 2008

GAMS/IDE bug

Ctrl-T eats up too many characters:


› // hello
› -10


In both cases Ctrl-T should remove blanks up-to the first non-blank character. However it will also remove the // and - characters.

If this happens, use Ctrl-Z to undo.

MWsnap for making screen shots

http://www.mirekw.com/winfreeware/mwsnap.html is a useful tool to create screen shots. I use it a lot.