Skip to content

Commit

Permalink
Merge branch 'metroMap' of github.com:Marika-K/gurobi-optimods into m…
Browse files Browse the repository at this point in the history
…etroMap
  • Loading branch information
Marika-K committed Jun 24, 2024
2 parents 29f5b3a + 0c189c6 commit 4b2a792
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 42 deletions.
1 change: 1 addition & 0 deletions .github/workflows/wheel-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- name: Fetch dependencies for offline install
run: |
pip wheel --wheel-dir=dist gurobipy pandas numpy scipy gurobipy-pandas
pip wheel --wheel-dir=dist "numpy<2"
- name: Install from built wheel
run: |
python -m pip install --find-links dist --no-index --only-binary=:all: gurobi-optimods
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
develop:
python -m pip install pip setuptools wheel --upgrade
python -m pip install -e .[examples]
python -m pip install -r docs/requirements.txt
python -m pip install -r docs/requirements-base.txt
python -m pip install sphinx-autobuild pre-commit
pre-commit install

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pip install gurobi-optimods

## Documentation

Full documentation for `gurobi-optimods` is hosted on [readthedocs](https://gurobi-optimization-gurobi-optimods.readthedocs-hosted.com/en/stable).
Full documentation for `gurobi-optimods` is hosted on [readthedocs](https://gurobi-optimods.readthedocs.io/en/stable).

## License

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ sphinxcontrib-qthelp==1.0.7
sphinxcontrib-serializinghtml==1.1.10
tabulate==0.9.0
typing_extensions==4.11.0
urllib3==2.2.1
urllib3==2.2.2
webencodings==0.5.1
22 changes: 22 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@
numpydoc_xref_ignore = {"optional", "or", "of"}


# -- doctest configuration

doctest_global_setup = """
def size_limited_license():
result = False
try:
import gurobipy as gp
from gurobipy import GRB
with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model:
x = model.addVars(2001)
model.optimize()
except gp.GurobiError as e:
if e.errno == GRB.Error.SIZE_LIMIT_EXCEEDED:
result = True
return result
"""


# -- Docstring preprocessing for autodoc

autodoc_typehints = "none"
Expand Down
6 changes: 3 additions & 3 deletions docs/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Development Environment

To set up your development environment:

1. Create and activate a Python 3.8 virtual environment using your preferred
tool. We maintain compatibility with Python 3.8 and above, so developing
using 3.8 locally will ensure your contributions are compatible.
1. Create and activate a Python virtual environment using your preferred tool.
You can use any currently supported Python version for development (versions
3.8 through 3.12).
2. Run ``make develop`` from the top level of the repository. This command will
install (using ``pip``) all packages required to run the unit tests, run the
doc tests, and build the sphinx documentation. It will also install
Expand Down
22 changes: 11 additions & 11 deletions docs/source/mods/line-optimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ This problem is an example of a classical network design problem.
There are different approaches and models to solve the line optimization problem.
A general overview on models and methods is given by Schoebel :footcite:p:`schoebel2012`.

For this optimod we assume we are given a public transportation network, being
For this optimod we assume we are given a public transportation network:
a set of stations and the direct links between them. We are given the
origin-destination (OD) demand, i.e., it is known how many passengers want to
travel from one station to another in the network within a considered time horizon.
We are also given a set of possible *lines*. A line is a path a public
transportation network. We call a subset of these lines where each line is
associated with a frequency a line plan. The optimod computes a line plan with
minimum cost such that the capacity of the chosen lines sufficient to transport
origin-destination (OD) *demand*, i.e., it is known how many passengers want to
travel from one station to another in the network within the considered time horizon.
We are also given a set of possible *lines*. A line is a path in a public
transportation network. We call *line plan* a subset of these lines where each line is
associated with a frequency. The optimod computes a line plan with
minimum cost such that the capacity of the chosen lines is sufficient to transport
all passengers.

We provide two different strategies to find a line plan with minimum cost:
Expand All @@ -39,9 +39,9 @@ vertices :math:`V` represent the stations and the set of edges
:math:`E` represent all possibilities to travel from one station to another without
an intermediate station.
A directed edge :math:`(u,v)\in E` has the attribute time :math:`\tau_{uv}\geq 0` that
represents the amount of time needed traveling from :math:`u` to :math:`v`.
For each pair of nodes :math:`u,v\in V` a demand :math:`d_{uv}\geq 0` can be defined.
The demand represents the number of passengers that want to travel from :math:`u`
represents the amount of time needed to travel from :math:`u` to :math:`v`.
For each pair of nodes :math:`u,v\in V` a demand :math:`d_{uv}\geq 0` is given.
The demand represents the number of passengers who want to travel from :math:`u`
to :math:`v` in the considered time horizon. Let :math:`D` be the set of all node pairs with
positive demand. This set is also called OD pairs.
Further given is a set of lines :math:`L`. A line :math:`l\in L` contains the stations it traverses
Expand All @@ -53,7 +53,7 @@ A line has the following additional attributes:
- operating cost: :math:`c_{l}\geq 0` for operating the line once in the given time horizon
- capacity: :math:`\kappa_{l}\geq 0` when operating the line :math:`l` once in the given time horizon

Additionally, we have a given list of frequencies. The frequencies define the possible
Additionally, we are given a list of frequencies. The frequencies define the possible
number of operations for the lines in the given time horizon.
If a line :math:`l` is operated with frequency :math:`f` the overall cost for the line is
:math:`C_{lf}=C_l + c_{lf}\cdot f` and the total capacity provided by the line is
Expand Down
2 changes: 2 additions & 0 deletions docs/source/mods/metromap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ The OptiMod can be run as follows:

.. doctest:: solve
:options: +NORMALIZE_WHITESPACE
:skipif: size_limited_license()

>>> from gurobi_optimods import datasets
>>> from gurobi_optimods.metromap import metromap
Expand Down Expand Up @@ -520,6 +521,7 @@ this OptiMod. Here is an example of how this could be done


.. testcode:: combine
:skipif: size_limited_license()

# import all requirements
import networkx as nx
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
dependencies = [
"gurobipy[matrixapi]>=10.0.3",
"gurobipy-pandas>=1.0.0",
"numpy",
"numpy<2",
"pandas",
"scipy>=1.8.0",
]
Expand Down
2 changes: 1 addition & 1 deletion src/gurobi_optimods/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__doc__ = "Gurobi OptiMods"

__version__ = "2.0.1dev0"
__version__ = "2.0.1"
14 changes: 2 additions & 12 deletions tests/opf/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import pathlib
import unittest

import gurobipy as gp

from gurobi_optimods.datasets import load_opf_example, load_opf_extra
from gurobi_optimods.opf import (
compute_violations,
Expand All @@ -16,23 +14,15 @@
violation_plot,
)

from ..utils import size_limited_license

# If plotly is not installed, tests will be skipped
try:
import plotly
except ImportError:
plotly = None


def size_limited_license():
with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model:
model.addVars(2001)
try:
model.optimize()
return False
except gp.GurobiError:
return True


@unittest.skipIf(plotly is None, "plotly is not installed")
class TestGraphicsCase9(unittest.TestCase):
def setUp(self):
Expand Down
12 changes: 1 addition & 11 deletions tests/opf/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@
import random
import unittest

import gurobipy as gp

from gurobi_optimods.datasets import load_opf_example
from gurobi_optimods.opf import solve_opf


def size_limited_license():
with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model:
model.addVars(2001)
try:
model.optimize()
return False
except gp.GurobiError:
return True
from ..utils import size_limited_license


class TestInvalidData(unittest.TestCase):
Expand Down
17 changes: 17 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ def skip_wrapper(*args, **kwargs):
raise

return skip_wrapper


def size_limited_license():
result = False

try:
import gurobipy as gp
from gurobipy import GRB

with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model:
x = model.addVars(2001)
model.optimize()
except gp.GurobiError as e:
if e.errno == GRB.Error.SIZE_LIMIT_EXCEEDED:
result = True

return result

0 comments on commit 4b2a792

Please sign in to comment.