Table of Contents
How to NOT make a database
I am working with a database of volumes/surface of forest in France… I have several sheets, because in the middle the inventory system of course changed.
But what make me extremely angry is the layout and encoding of the fields..
Species: in some sheets we have the species name in French, in others in French with some other remarks, in other in capital…
Department: sometimes we have the name, sometimes we have the code…
Time: sometimes we have the year, sometimes the year is a column, sometimes the year is the “cycle” of the inventory (a different year in each department)..
£$%/&%&“£$”#####!!!|“££$”£$% !!!!!
Soluzione a Cheryl's Birthday - Quand'è il compleanno di Cheryl
La soluzione al problema del Cheryl's Birthday - Quand'è il compleanno di Cheryl ?
Allora, incominciamo. Alberto sa il mese e sa che Bernardo sa il giorno. Siccome dice che sa che Bernardo non sa il compleanno deve trattarsi di un mese in cui tutti i giorni hanno i doppioni, sennò non potrebbe sapere che Bernardo non lo sa.
Quindi il mese è o Luglio o Agosto. E siamo a buon punto della soluzione.
Bernardo dice che prima non lo sapeva, ma adesso lo sa. Lui ha fatto il nostro stesso ragionamento ma in più sa il giorno. Deve trattarsi quindi di un giorno che prima stava in entrambi gli insiemi (Maggio, Giugno) e (Luglio, Agosto) mentre adesso, con la nuova informazione che il mese è Luglio o Agosto, Alberto riesce ad identificare in maniera univoca.
Questi possono essere solo 16 Luglio, 15 Agosto, 17 Agosto (se fosse 14 Luglio o 14 Agosto, Bernardo ancora non potrebbe sapere quand'è il compleanno).
Adesso, il fatto che lui lo sappia rivela anche ad Alberto che l'unica data possibile è il … 16 luglio.
Se infatti fosse Agosto, Alberto saprebbe che nonostante la sua rivelazione Bernardo non sarebbe ancora capace di sapere il compleanno (potrebbe essere il 15 o il 17). Solo se è Luglio, ALberto potrebbe essere certo che si tratti del 16.
E questo risolve il problema.
Cheryl's Birthday - Quand'è il compleanno di Cheryl ?
Traduzione italiana del problema del compleanno di Cheryl (Cheryl's Birthday):
Alberto e Bernardo vogliono diventare amici di Cheryl, e vogliono sapere quand'è il suo compleanno. Cheryl gli dà una lista di 10 possibili date:
| 15 Maggio | 16 Maggio | 19 Maggio |
| 17 Giugno | 18 Giugno | |
| 14 Luglio | 16 Luglio | |
| 14 Agosto | 15 Agosto | 17 Agosto |
Cheryl poi dice separatamente ad Alberto e Bernardo rispettivamente il mese ed il giorno del suo compleanno.
Alberto: Non so quando sia il compleanno di Cheryl, ma so che pure Bernardo non lo sa.
Bernardo: Non sapevo quand'è il compleanno di Cheryl, ma adesso lo so.
Alberto: Allora adesso anch'io lo so
Quand'è quindi il compleanno di Cheryl ?
A Pyomo tutorial for GAMS users
Updates:
- 2015.01.12: Updated to run under Pyomo 4. See previous revisions if you still use Pyomo 3.
Pyomo (Python Optimisation Modeling Object) 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 Sandia National Laboratories and appeared in 2008 as an open source project.
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 Pyomo. There may be two reasons for someone to with to use Pyomo instead of GAMS.
The most obvious one, even if often it isn't the key driver, is that GAMS is a commercial software while Pyomo 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, Pyomo would still require the user to buy a licence to use a specific commercial solvers. However Pyomo 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.
Pyomo, at the opposite, is both open source and.. it's python!
You have plenty of development environment to choose from, a clear modern language, the possibility to interface your model with third party libraries.. all of this basically for free.
While there are some reports of pyomo being somehow slower that GAMS it really depends. In my case it is actually much faster, as the IPOPT version that is embedded in GAMS uses the MUMPS linear solver, while on my system I have IPOPT compiled with the much more performing ma27 linear solver. That's part of the flexibility you gain in using pyomo in place of GAMS.
So let's start. We will see how to code the trasnport.gms problem, the one that ship as default example in GAMS1), using Pyomo. 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
<< Newer entries | Older entries >>


