Skip to content

Commit

Permalink
changed docs + fixed typo in xpress solver
Browse files Browse the repository at this point in the history
  • Loading branch information
pchtsp committed Jan 15, 2024
1 parent e602a40 commit d440ce4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions doc/source/CaseStudies/a_blending_problem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ the data.
:lines: 10-61

The ``prob`` variable is created to contain the formulation, and the
usual parameters are passed into :obj:`~pulp.LpProblem`.
usual parameters are passed into :class:`~pulp.LpProblem`.

.. literalinclude:: ../../../examples/WhiskasModel2.py
:lines: 63-64
Expand All @@ -330,7 +330,7 @@ Further list comprehensions are used to define the other 5 constraints, which ar
.. literalinclude:: ../../../examples/WhiskasModel2.py
:lines: 75-92

Following this, the :ref:`writeLP<writeLP>` line etc follow exactly the same as
Following this, the :meth:`~pulp.LpProblem.writeLP` line etc follow exactly the same as
in the simplified example.

The optimal solution is 60% Beef and 40% Gel leading to a objective
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"http://docs.python.org/3": None}
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
27 changes: 17 additions & 10 deletions doc/source/guides/how_to_configure_solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ PuLP has some helper functions that permit a user to query which solvers are ava
import pulp as pl
solver_list = pl.listSolvers()
print(solver_list)
# ['GLPK_CMD', 'PYGLPK', 'CPLEX_CMD', 'CPLEX_PY', 'CPLEX_DLL', 'GUROBI', 'GUROBI_CMD', 'MOSEK', 'XPRESS', 'PULP_CBC_CMD', 'COIN_CMD', 'COINMP_DLL', 'CHOCO_CMD', 'MIPCL_CMD', 'SCIP_CMD']
If passed the `onlyAvailable=True` argument, PuLP lists the solvers that are currently available::

import pulp as pl
solver_list = pl.listSolvers(onlyAvailable=True)
print(solver_list)
# ['GLPK_CMD', 'CPLEX_CMD', 'CPLEX_PY', 'GUROBI', 'GUROBI_CMD', 'PULP_CBC_CMD', 'COIN_CMD']

Also, it's possible to get a solver object by using the name of the solver. Any arguments passed to this function are passed to the constructor:
Expand All @@ -33,7 +35,7 @@ In the next sections, we will explain how to configure a solver to be accessible
What is an environment variable
--------------------------------------

An environment variable is probably better explained `somewhere else <https://en.wikipedia.org/wiki/Environment_variable>`_. For the sake of this document, it is a text value stored during your session that allows you to configure some applications that make use of them. For example, when you write:
An environment variable is probably better explained `somewhere else <https://en.wikipedia.org/wiki/Environment_variable>`_. For the sake of this document, it is a text value stored during your session that allows you to configure some applications that make use of them. For example, when you write::

python

Expand Down Expand Up @@ -76,11 +78,11 @@ Imagine using the ``CPLEX_CMD`` solver, the first one is really simple:
model += _var + _var2 == 1
result = model.solve(solver)
The only to do was to look for the 'cplex.exe' file (in Windows, although in Linux and Mac is something similar but with 'cplex') and pass the absolute path to the solver.
The only thing to do was to look for the 'cplex.exe' file (if you're in Windows, for Linux and Mac you look for the 'cplex' file) and pass the absolute path to the solver.

The second one is a little more cumbersome but you only do it once per machine. You need to configure the ``PATH`` environment variable to include the path to the ``C:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\bin\x64_win64`` directory.

Here is one random guide to editing environment variables in: `Windows <https://opentechguides.com/how-to/article/windows-10/113/windows-10-set-path.html>`_ or `Linux or Mac <https://askubuntu.com/questions/730/how-do-i-set-environment-variables>`_. The idea is that once it is correctly configured you can forget about it (until you change pc or solver version).
Here is one random guide to editing environment variables in: `Windows <https://opentechguides.com/how-to/article/windows-10/113/windows-10-set-path.html>`_ and `Linux or Mac <https://askubuntu.com/questions/730/how-do-i-set-environment-variables>`_. The idea is that once it is correctly configured you can forget about it (until you change pc or solver version).

Once we have done that, we just do something very similar to the previous example:

Expand All @@ -107,15 +109,15 @@ Whatever the reason, it's better to be safe than sorry and this means knowing wh
CPLEX
*******

**Linux / Mac: add the following lines to the ~.bashrc (or ~.profile or /etc/profile or /etc/bash.bashrc) file**::
**Linux / Mac**: add the following lines to the ~.bashrc (or ~.profile or /etc/profile or /etc/bash.bashrc) file::

export CPLEX_HOME="/opt/ibm/ILOG/CPLEX_Studio128/cplex"
export CPO_HOME="/opt/ibm/ILOG/CPLEX_Studio128/cpoptimizer"
export PATH="${PATH}:${CPLEX_HOME}/bin/x86-64_linux:${CPO_HOME}/bin/x86-64_linux"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${CPLEX_HOME}/bin/x86-64_linux:${CPO_HOME}/bin/x86-64_linux"
export PYTHONPATH="${PYTHONPATH}:/opt/ibm/ILOG/CPLEX_Studio128/cplex/python/3.5/x86-64_linux"

**Windows: add the following environment variables (via the command line or the graphical user interface)**::
**Windows**: add the following environment variables (via the command line or the graphical user interface)::

set CPLEX_HOME=C:/Program Files/IBM/ILOG/CPLEX_Studio128/cplex
set CPO_HOME=C:/Program Files/IBM/ILOG/CPLEX_Studio128/cpoptimizer
Expand All @@ -126,13 +128,13 @@ CPLEX
GUROBI
*******

**Linux / Mac: add the following lines to the ~.bashrc (or ~.profile or /etc/profile or /etc/bash.bashrc) file**::
**Linux / Mac**: add the following lines to the ~.bashrc (or ~.profile or /etc/profile or /etc/bash.bashrc) file::

export GUROBI_HOME="/opt/gurobi801/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${GUROBI_HOME}/lib"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"

**Windows: add the following environment variables (via the command line or graphical user interface)**::
**Windows**: add the following environment variables (via the command line or graphical user interface)::

set GUROBI_HOME=/opt/gurobi801/linux64
set PATH=%PATH%;%GUROBI_HOME%/bin
Expand All @@ -142,7 +144,7 @@ GUROBI
Configuring where the CMD solvers write their temporary files
---------------------------------------------------------------------------

In the case of solver APIs that use the command line (again, those that end in ``CMD``, sometimes a user wants to control where the files are written. There are plenty of options.
In the case of solver APIs that use the command line (again, those that end in ``CMD``), sometimes a user wants to control where the files are written. There are plenty of options.

By default, PuLP does not keep the intermediary files (the \*.mps, \*.lp, \*.mst, \*.sol) and they are written in a temporary directory of the operating system. PuLP looks for the TEMP, TMP and TMPDIR environment variables to write the file (in that order). After using them, PuLP deletes them. If you change any of these environment variables before solving, you should be able to choose where you want PuLP to write the results.

Expand Down Expand Up @@ -191,6 +193,10 @@ PuLP has the integrations with the official python API solvers for the following
* Gurobi (GUROBI)
* Cplex (CPLEX_PY)
* Xpress (XPRESS_PY)
* HiGHS (HiGHS)
* SCIP (SCIP_PY)
* XPRESS (XPRESS_PY)
* COPT (COPT)

These API offer a series of advantages over using the command line option:

Expand All @@ -212,14 +218,15 @@ Installing GUROBI

For this solver to work, the only option is to install the python package that comes with the gurobi installation.

Following my installation paths it would be (Linux):
Following my installation paths it would be (Linux)::

cd /opt/gurobi801/linux64/
sudo python3 setup.py install

As you can see, it is necessary to have admin rights to install it.

.. _solver-specific-config:

Using solver-specific functionality
**********************************************

Expand Down
2 changes: 1 addition & 1 deletion pulp/apis/xpress_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def buildSolverModel(self, lp):
# passed explicitly into the constructor.
for option in self.options:
if isinstance(option, tuple):
name = optione[0]
name = option[0]
value = option[1]
else:
fields = option.split("=", 1)
Expand Down
8 changes: 5 additions & 3 deletions pulp/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ def addVariable(self, variable):
"""
Adds a variable to the problem before a constraint is added
@param variable: the variable to be added
:param variable: the variable to be added
"""
if variable.hash not in self._variable_ids:
self._variables.append(variable)
Expand All @@ -1572,7 +1572,7 @@ def addVariables(self, variables):
"""
Adds variables to the problem before a constraint is added
@param variables: the variables to be added
:param variables: the variables to be added
"""
for v in variables:
self.addVariable(v)
Expand Down Expand Up @@ -1686,7 +1686,7 @@ def extend(self, other, use_objective=True):
extends an LpProblem by adding constraints either from a dictionary
a tuple or another LpProblem object.
@param use_objective: determines whether the objective is imported from
:param bool use_objective: determines whether the objective is imported from
the other problem
For dictionaries the constraints will be named with the keys
Expand Down Expand Up @@ -1742,6 +1742,7 @@ def writeMPS(
:param bool rename: if True, normalized names are used for variables and constraints
:param mip: variables and variable renames
:return:
Side Effects:
- The file is created
"""
Expand All @@ -1763,6 +1764,7 @@ def writeLP(self, filename, writeSOS=1, mip=1, max_length=100):
:param str filename: the name of the file to be created.
:return: variables
Side Effects:
- The file is created
"""
Expand Down
8 changes: 4 additions & 4 deletions pulp/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def splitDict(data):
"""
Split a dictionary with lists as the data, into smaller dictionaries
:param data: A dictionary with lists as the values
:param dict data: A dictionary with lists as the values
:return: A tuple of dictionaries each containing the data separately,
with the same dictionary keys
Expand All @@ -198,9 +198,9 @@ def read_table(data, coerce_type, transpose=False):
simple script
::return: a dictionary of with the keys being a tuple of the strings
in the first row and colum of the table
::param data: the multiline string containing the table data
::param coerce_type: the type that the table data is converted to
::param transpose: reverses the data if needed
:param str data: the multiline string containing the table data
:param coerce_type: the type that the table data is converted to
:param bool transpose: reverses the data if needed
Example:
>>> table_data = '''
Expand Down

0 comments on commit d440ce4

Please sign in to comment.