A JuMP tutorial for GAMS users

JuMP (Julia for Mathematical Optimization) is an Algebraic Modelling Language (AML) that allows to write optimisation problems using a concise mathematical formulation, acting as interface to the specific solver engine API. For non-linear optimisation problems it allows to keep a high-level approach that doesn't require the modeller to compute the Jacobian or the Hessian.
It is developed by the MIT Operations Research Center and appeared in 2013 as an open source package of the relatively new Julia programming language.

GAMS (The General Algebraic Modeling System) does more or less the same things and appeared in the '70s as a project of the World Bank. GAMS is hence a very mature project (maybe too mature) with a lot of followers in the economic domain, where it is used mainly to solve equilibria problems.

This mini-tutorial is intended for gams users that want to try JuMP. There may be two reasons for someone to with to use JuMP instead of GAMS.
The most obvious one, even if often it isn't the key driver, is that GAMS is a commercial software while JuMP being open-source is free both as freedom and as a free beer.
While for GAMS a licence for the underlying solver engine is often included with a particular version of GAMS, JuMP would still require the user to buy a licence to use a specific commercial solvers. However JuMP interfaces with both GLPK (for linear and mixed-integer programming) and IPOPT (for non-linear optimisation) open-source solvers, both of which are top on their classes, leaving the necessity to acquire a licence for a commercial solver to niche cases.
The second reason (and, to me, the most important one) resides in the language features and in the availability of development environments. GAMS uses a VERY ODD syntax, somehow derived from the Cobol language, that is very distant from any programming language in use nowadays. For example a macro mechanism to provide an elementary way to structure the code in reusable components has been introduced only in GAMS 22.9. Its own editor is also very terrible, but as most text editors do not provide a GAMS syntax highlighting, it's still the most common way to code in GAMS.

JuMP, at the opposite, is both open source and it allow to write the model in a powerful general-purpose language like Julia
You have plenty of development environment to choose from (e.g. Jupiter, Juno), a clear modern language, the possibility to interface your model with third party libraries.. all of this basically for free.
It is also, at least for my user case, much faster than GAMS. Aside the preparation of the model to pass to the solver, where it is roughly equivalent, in the solver execution I can benefit of having on my system a version of IPOPT compiled with the much more performing ma27 linear solver, while for GAMS I would have to rely on the embedded version that is compiled with the MUMPS linear solver. That's part of the flexibility you gain in using JuMP in place of GAMS. That's said, for people that don't need such flexibility, the package automatically install a local pre-compiled version of the solver, so just adding the package relative to the solver is enough to start writing the model. Even more, for people that doesn't care too much about performances, there is a service on JuliaBox.com that allows to run Julia/JuMP scripts for free in the browser, without anything to install on the local computer.

So let's start. We will see how to code the trasnport.gms problem, the one that ship as default example in GAMS1), using JuMP. For a fictions product, there are three canning plants and three markets and the objective of the model is to find the optimal allocation of products between plants and markets that minimises the (transport) costs.
GAMS equivalent code is inserted as single-dash comments. The original GAMS code needs slightly different ordering of the commands and it's available at http://www.gams.com/mccarl/trnsport.gms

→ Read more...

2017/02/03 14:03 · antonello · 2 Comments

My program for a better France

ok, I am an etranger, so no way I can run for the French Presidencial elections :-) Still, I think I lived long enough in this country to have my own opinion on what could be done to improve the welfare of its citizens, in a gagnè-gagnè way that increases efficiency and make everyone better off.

So, these are my points.. I'll be very quick - time is a scarce resource - but if I'll have more time I'll expand it:

→ Read more...

2017/01/13 09:33 · antonello · 1 Comment

Etica e gerarchia delle libertà

“La mia libertà finisce dove comincia la vostra.” (M.L. Kink).

Bella frase ma assolutamente inutile per gestire i conflitti, ovvero interessi multipli sulla medesima risorsa.

In tal caso il mio apprroccio etico è di definire una gerarchia delle libertà, ove la mia libertà di livello inferiore si arretra quando infrange la libertà superiore di un altro.

In ordine questi livelli sono:

Libertà dell'esistenza, libertà di pensiero, libertà di star bene, libertà di espressione, libertà di agire.

Come vedete non esiste per me una specifica libertà di religione, in quanto la considero nella libertà di pensiero.

(Si, questo articolo è da sviluppare..)

2016/08/19 10:14 · antonello · 0 Comments

Terrorismo: combatterne le idee e il terreno su cui esse prosperano

Vivendo in Francia ho già scritto che non sarebbe del tutto sbagliato dare la colpa del terrorismo islamico agli urbanisti francesi di qualche decina d'anni fa..

E' fondamentale a mio avviso considerare che un attacco terroristico ha due drivers: la parte “network” e quella individuale. La prima è legata alla specifica ideologia che spinge verso l'atto, che può agire come una semplice istigazione/indottrimento del “lupo solitario” o una più complessa rete che procura le armi, aiuta nella formazione, ecc.. E' nel suo contrasto che si fonda la “lotta al terrorismo” classica, l'intelligence, i controlli alla frontiera, le bombe sull'IS ecc… Chi nega l'importanza di queste azioni nega l'evidenza di una “ideologia” di morte e fanatismo che purtroppo ben esiste.

Ma è sul driver individuale che invece, specialmente in Francia, si è fatto ben poco. Il teppistello viene indottrinato al terrorismo perchè così sfoga le sue repressioni, finalmente ha uno scopo di vita, ha coscienza che “lui vale”. “Uccido ergo sum” per fare il verso al motto di cartesiana memoria.

Non è un caso che questi attacchi alla Francia avvengano in una condizione economica sfavorevole e vengono perpetrati da “giovani maschi” che non hanno ancora trovato una loro stabilità economica, sociale, emotiva, famigliare…

Ma non sarebbe allora utile intervenire anche su questo fronte? Investire più risorse sui corsi di francese per gli immigrati ? In centri di supporto all'integrazione che facilitino anche a queste fasce di popolazione l'utilizzo dei servizi forniti dall'amministrazione burocratica francese, che esistono ma che sono tutt'altro che semplici ? Tra l'altro con il doppio dividendo di favorire anche la crescita ecomica.

Certo non si riuscirà mai ad evitare la formazione di alcun pazzoide represso, ma è dalla sinergia di queste due azioni, e non dall'intervento isolato su una di essa, che la Francia, e gli altri paesi occidentali, possono sperare in una normalizzazione dei rapporti tra occidente e mondo arabo.

2016/07/15 11:36 · antonello · 0 Comments

Brexit: an historic decision dictated by contingent reasons

So much it has been said, and so much will be said about this night that will have repercussions for an entire generation of British but also European citizens and, more indirectly, for the rest of the world.

Only a few months ago polls showed an advantage of Remain in double figures. What happened? They were completely bogus polls? British people have had in the meantime the opportunity to inform themselves and to better understand the issues at stake and then decide with greater awareness?

This is the view of those who argue the priority of direct democracy, that see the referendum as the highest expression of the will of the sovereign people.

I have, however, a different view. The referendum has been won by the Brexit side for a purely conjunctural reason and, at the end, fortuitous: who had the led of the Brexit campaign, the people who were there at that time, has been more talented of those who were found to drive the campaign of Remain.

They were better at grasping the feelings of the electorate. They won for the heart, partly helped by the not exactly idyllic feeling that the population (not just the British one) has in this historic period for the political representatives.

By contrast, those responsible for the campaign Remain, on the one hand have failed to communicate the true values ​​associated to EU membership, and on the other, focusing on paternalism (“Beware, if you vote for Brexit it will happens the end of the world!”), they make themselves even more unpleasant.

It is not just the ineptitude and the low level of confidence of Cameron to be blamed, if the Remain lost. Even the “external campaign” has certainly not helped. Mr. Junker, the President of the European Commission (another not really “loved” politician) and other European leaders have insisted on the message “If you choose Brexit, we will punish you!” …not really a message of peace and love for the British people.

In short, supporters of Remain, instead of focusing on the common values ​​of the European project, the friendship between the people of UK and the other European nations, have bogged down in warnings about the financial and commercial risks of Brexit, giving even more the impression of a gray and bureaucratic Europe.

Yet another indicator of how this vote can be seen as a protest vote, made by heart more than by reason, has been the prior assessments of the voting made by the brokers. All (or most) were convinced that the Remain still would have won. In these conditions, I can express my protest vote more serenely, without worrying too much about its consequences (this is also the reason why in the voting for the European Parliament, considered quite useless, they often prevail protest movements in comparison to national elections).

Then, British citizens have really voted because they consider an England without Europe more efficient and more secure? In my opinion no (after all, rationally, they were already out of the Euro currency and outside Shengen). They voted because the campaign of Remain has paradoxically managed to make them feel Europe even more distant, and perhaps more than the financial and commercial problems (which will be resolved) this is the most worrying legacy this election will leaves.

2016/06/24 09:38 · antonello · 1 Comment

Older entries >>

1)
yes, the default GAMS example is named “trasnport”
personal/blog/home.txt · Last modified: 2014/05/10 15:11 (external edit)
CC Attribution-Noncommercial-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0