Docsity

same like before notes, Lecture notes of Business Statistics

Partial preview of the text

Download same like before notes and more Lecture notes Business Statistics in PDF only on Docsity!

Siamak Naderi

Optimisation Models

Use Anaconda

  • Install Anaconda
    • https://www.anaconda.com/download
    • Windows/Mac OS X/Linux
    • Includes several packages for scientific computing already
    • Supports easy installation of Pyomo and solvers
  • Install Pyomo, solvers, and other packages:
    • From a terminal window, type: 1. conda install - c https://conda.anaconda.org/conda-forge pyomopyomo.extras 2. conda install glpkipopt_bin-c cachemeorg

Pyomo

  • It is Pythonic and open source
  • Solver agnostic: can use multiple open source or commercial solvers

(GLPK, IPOPT, Gurobi, CPLEX, …)

  • High level API
  • Extended documentation
  • Can solve advanced optimisation problems (LP, NLP, IP, …)

Install with pip in Python

  • Install Pyomo
    • pip install Pyomo

Install with pip in Python

  • Install Pyomo
    • pip install Pyomo

Pyomo

  • Pyomo objects exist within the pyomo.environ namespace:

Pyomo

  • Pyomo objects exist within the pyomo.environ namespace:
    • import pyomo.environ
    • model = pyomo.environ.ConcreteModel()
  • To save time in terms of typing, we will import the core Pyomo classes into the main namespace:

Pyomo

  • Pyomo objects exist within the pyomo.environ namespace:
    • import pyomo.environ
    • model = pyomo.environ.ConcreteModel()
  • To save time in terms of typing, we will import the core Pyomo classes into the main namespace: - from pyomo.environ import * - model = ConcreteModel()

13 Core modelling components in Pyomo

  • Var: The Var component is used to represent optimization decision variables. Pyomo supports continuous and integer variables and includes several pre-defined domains.

14 Core modelling components in Pyomo

  • Var: The Var component is used to represent optimization decision variables. Pyomo supports continuous and integer variables and includes several pre-defined domains.
  • Objective: The Objective component defines the function to be optimized by the solver. This component contains the expression used to define the objective function, and a flag to indicate the sense (maximise or minimise).

16 Core modelling components in Pyomo

  • Var: The Var component is used to represent optimization decision variables. Pyomo supports continuous and integer variables and includes several pre-defined domains.
  • Objective: The Objective component defines the function to be optimized by the solver. This component contains the expression used to define the objective function, and a flag to indicate the sense (maximise or minimise).
  • Constraint: Constraints are used to define additional restrictions on the decision variables. The Constraint component contains expressions and the appropriate relational operator. Pyomo supports equality (==) and general inequality (<= or >=) constraints.
  • Expression: The Expression component can be used to create a Pyomo expression that can be reused in different parts of a Pyomo model. This is useful for representing common sub-expressions for memory efficiency. Similar to mutable parameters, the underlying expression can be changed between calls to the solver.

17 Core modelling components in Pyomo

  • Var: The Var component is used to represent optimization decision variables. Pyomo supports continuous and integer variables and includes several pre-defined domains.
  • Objective: The Objective component defines the function to be optimized by the solver. This component contains the expression used to define the objective function, and a flag to indicate the sense (maximise or minimise).
  • Constraint: Constraints are used to define additional restrictions on the decision variables. The Constraint component contains expressions and the appropriate relational operator. Pyomo supports equality (==) and general inequality (<= or >=) constraints.
  • Expression: The Expression component can be used to create a Pyomo expression that can be reused in different parts of a Pyomo model. This is useful for representing common sub-expressions for memory efficiency. Similar to mutable parameters, the underlying expression can be changed between calls to the solver.
  • Set: The Set component represents a collection of data that can include numeric (e.g., integer), or symbolic (e.g., string) elements. They are most commonly used to define valid indices for other components. Several common set operations are also supported.

Pyomo: the model from pyomo.environ import * model = ConcreteModel() All Pyomo model starts with this; it tells Python to load the Pyomo Modeling Environment

Pyomo: the model from pyomo.environ import * model = ConcreteModel() All Pyomo model starts with this; it tells Python to load the Pyomo Modeling Environment Creates an empty sheet as model