Monday, September 27, 2010

Student mails

I get many mails from students asking for help. I usually try to give a small hint and direct them to get more help from their supervisor. Here are some examples.

I work for a supply chain management company, and we need some help on the attached exercise we have been given as an internal training exercise. Can you help? Attached is the project and all of the data and mod files. The deadline is Friday. If you can help, please provide a price quotation.

Answer: I would suggest to takes this up with your instructor. I believe it can be conceived as inappropriate if I would step into this.

After my standard reply of "Talk to your supervisor. He/she is actually getting paid to help you." one sometimes get long stories of poor supervision by professors:

I am really, really sorry to bother you, but my supervisor does not know how to use CPlex, only one lecturer in Math department knows how to use CPlex, but he is very busy at the moment (his wife just got cancer), you are the only expert that I can count on, it is a critical part of my PhD thesis, I really, really need your help for my problem, would you please have a look at my question and give me some idea? Thank you billion times! Your help will be greatly appreciated!
Or sometimes shorter:
Me and my wife are in very difficult situation. She runs out of the scholarship and I have to go back to Kuwait with her and the family.

Of course if I send back a file with some results, I really should hide all details about who actually did the work. Secrecy is important here: 

Also can you change the following to STUDENTSNAME

Licensee: Erwin Kalvelagen                               G080731/0001CJ-WIN

Nobody know you are helping me please. My future is between your hands

Can you run GAMS economical model / Spread sheet please and put my name STUDENTSNAME everywhere please?

Some people are quite brazen in their request. This guy wants me to do his complete PhD work and he will find someone else to help me if I am too expensive:

What is your lump thump price tell I get my PhD to get two publication accepted and modify my GAMS RESULTS tell the committee is satisfied and teaching me what you did and prepare me also for defence?

What is the budget for the first publication is $? while how much you should be able to write the second publication for $?. you will make sure that those publications are of such a high standard that you will be able to find a journal which will accept both papers.

In case that this is more than my budget allows, then we can just do the GAMS part for me. Once this is done we might as well find someone else who can write you the two publications.

Does not look PhD supervisors are doing a good job if students think they can get away with such requests!

GAMS macro problems

I am working on a model that is using the preprocessor tool described in There were a few minor issues related to this tool:

  1. It does not really work very well with the GAMS IDE. You cannot click on the red error messages to bring you to the input line with the error.
  2. It does not handle combined use in equations and parameter assignments in post-solve reporting very well.

The documentation of the new $macro facility in GAMS (, section “The GAMS Macro Facility” ) seems to indicate that it can be used to replace the preprocessor tool: just use $macro and use set.local where needed. Unfortunately that is not completely true. Especially the sentence “The .local feature has been added to ensure local use and eliminates the need for new alias definitions.” is plain wrong.

Here is a simple model to illustrate the problem:

$sysinclude gams-f

set i /i1*i3/;
alias (i,j);

parameter x(i,j);
x(i,j) = normal(0,1);


parameter p(i) 'without macro/preproc';
p(i) =
sum(j, x(i,j));
display p;


y(i) ==
sum(j, x(i,j));

parameter p1(j) 'with preproc';
p1(j) = y(j);
display p1;


$macro y2(i) [sum(j.local, x(i,j))]

parameter p2(j) 'with macro';
p2(j) = y2(j);
display p2;

This shows:

----     26 PARAMETER p  without macro/preproc

i1  0.478,    i2 -3.533,    i3 -0.219

----     49 PARAMETER p1  with preproc

i1  0.478,    i2 -3.533,    i3 -0.219

----     57 PARAMETER p2  with macro

i1 -1.804,    i2 -1.804,    i3 -1.804

The cause can be found in the listing file:

35  ALIAS(FCN000,j);
39  parameter p1(j) 'with preproc';
40  p1(j) =
42  *       #### Preprocessor function replacement for Y ####
44  (
45   sum(FCN000, x(j,FCN000))
46  )
55  parameter p2(j) 'with macro';
56  p2(j) = [sum(j.local, x(j,j))];

Clearly the GAMS-F preprocessor handles this case correctly by introducing an alias. The $macro/.local combination does not do this and gives the wrong results. Instead of this .local hack it is needed to manually introduce an alias and use the aliased set where needed.

It is noted that overuse of these tools can lead to models that appear smaller (fewer equations and variables). However those models may be much denser and much more nonlinear (say in terms of nonlinear nonzero elements). Often larger, sparser and less non-linear models solve easier.

Monday, September 20, 2010

Google or-tools

The first OR-tool from Google is a preliminary constraint programming solver, available from here: The name “or-tools” seems to indicate we can expect more to come.

Wednesday, September 8, 2010

Efficient frontier-like analysis

I needed to perform an optimization run of the form:

image for different λ’s. Essentially something like an efficient frontier but in this case we have a MINLP (with semi-integer variables), so no smooth curve but instead some points.

In this case f(x) and g(x) were having different units and different magnitudes. In that case it is better to solve first:

imageand then use:

imageThis will get a (hopefully) better spread of the λ’s. See:

Of course if λ=0 or λ=1 is part of the λ’s we need to trace, then this actually does not require extra models to solve, just a different ordering: first do λ=0 and λ=1 to get f0 and g0 and then do the λ’s in between. As the λ’s are user specified, we needed a little bit of logic to handle this.