-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
838 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# COPT | ||
|
||
## Initial setup | ||
|
||
```python | ||
from pyoptinterface import copt | ||
|
||
model = copt.Model() | ||
``` | ||
|
||
You need to install COPT separately from the [COPT website](https://shanshu.ai/copt). After installing the software, you need to ensure the shared library of COPT is in the system path. | ||
|
||
- Windows: The `COPT_HOME` environment must be set to the COPT installation directory (like `C:\Program Files\copt71`). The COPT shared library `copt.dll` is located in the `bin` directory of the installation directory. The COPT installer usually sets this environment variable automatically, but you can also set it manually. | ||
|
||
- Linux: Add the COPT shared library to the `LD_LIBRARY_PATH` environment variable. The shared library `libcopt.so` is located in the `lib` directory of the installation directory. | ||
```bash | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/copt71/lib | ||
``` | ||
|
||
If you want to manage the license of COPT manually, you can create a `copt.Env` object and pass it to the constructor of the `copt.Model` object, otherwise we will initialize an implicit global `copt.Env` object automatically and use it. | ||
|
||
```python | ||
env = copt.Env() | ||
|
||
model = copt.Model(env) | ||
``` | ||
|
||
## The capability of `copt.Model` | ||
|
||
### Supported constraints | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Constraint | ||
- Supported | ||
* - <project:#model.add_linear_constraint> | ||
- ✅ | ||
* - <project:#model.add_quadratic_constraint> | ||
- ✅ | ||
* - <project:#model.add_second_order_cone_constraint> | ||
- ✅ | ||
* - <project:#model.add_sos_constraint> | ||
- ✅ | ||
|
||
::: | ||
|
||
### Supported [model attribute](#pyoptinterface.ModelAttribute) | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Attribute | ||
- Get | ||
- Set | ||
* - Name | ||
- ❌ | ||
- ❌ | ||
* - ObjectiveSense | ||
- ✅ | ||
- ✅ | ||
* - DualStatus | ||
- ✅ | ||
- ❌ | ||
* - PrimalStatus | ||
- ✅ | ||
- ❌ | ||
* - RawStatusString | ||
- ✅ | ||
- ❌ | ||
* - TerminationStatus | ||
- ✅ | ||
- ❌ | ||
* - BarrierIterations | ||
- ✅ | ||
- ❌ | ||
* - DualObjectiveValue | ||
- ✅ | ||
- ❌ | ||
* - NodeCount | ||
- ✅ | ||
- ❌ | ||
* - NumberOfThreads | ||
- ✅ | ||
- ❌ | ||
* - ObjectiveBound | ||
- ❌ | ||
- ❌ | ||
* - ObjectiveValue | ||
- ✅ | ||
- ❌ | ||
* - RelativeGap | ||
- ✅ | ||
- ✅ | ||
* - Silent | ||
- ✅ | ||
- ✅ | ||
* - SimplexIterations | ||
- ✅ | ||
- ❌ | ||
* - SolverName | ||
- ✅ | ||
- ❌ | ||
* - SolverVersion | ||
- ✅ | ||
- ❌ | ||
* - SolveTimeSec | ||
- ✅ | ||
- ❌ | ||
* - TimeLimitSec | ||
- ✅ | ||
- ✅ | ||
|
||
::: | ||
|
||
### Supported [variable attribute](#pyoptinterface.VariableAttribute) | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Attribute | ||
- Get | ||
- Set | ||
* - Name | ||
- ✅ | ||
- ✅ | ||
* - LowerBound | ||
- ✅ | ||
- ✅ | ||
* - UpperBound | ||
- ✅ | ||
- ✅ | ||
* - Domain | ||
- ✅ | ||
- ✅ | ||
* - PrimalStart | ||
- ✅ | ||
- ✅ | ||
* - Value | ||
- ✅ | ||
- ❌ | ||
|
||
::: | ||
|
||
### Supported [constraint attribute](#pyoptinterface.ConstraintAttribute) | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Attribute | ||
- Get | ||
- Set | ||
* - Name | ||
- ✅ | ||
- ✅ | ||
* - Primal | ||
- ✅ | ||
- ❌ | ||
* - Dual | ||
- ✅ | ||
- ❌ | ||
|
||
::: | ||
|
||
|
||
## Solver-specific operations | ||
|
||
### Parameter | ||
|
||
For [solver-specific parameters](https://guide.coap.online/copt/en-doc/parameter.html), we provide `get_raw_parameter` and `set_raw_parameter` methods to get and set the parameters. | ||
|
||
```python | ||
model = copt.Model() | ||
|
||
# get the value of the parameter | ||
value = model.get_raw_parameter("TimeLimit") | ||
|
||
# set the value of the parameter | ||
model.set_raw_parameter("TimeLimit", 10.0) | ||
``` | ||
|
||
### Attribute | ||
|
||
COPT supports [attribute](https://guide.coap.online/copt/en-doc/attribute.html) for the model. We provide `model.get_raw_attribute(name:str)` to get the value of attribute. | ||
|
||
### Information | ||
|
||
COPT provides [information](https://guide.coap.online/copt/en-doc/information.html) for the model components. We provide methods to access the value of information. | ||
|
||
- Information of variable: `model.get_variable_info(variable, name: str)` | ||
- Information of constraint: `model.get_constraint_info(constraint, name: str)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
# Gurobi | ||
|
||
## Initial setup | ||
|
||
```python | ||
from pyoptinterface import gurobi | ||
|
||
model = gurobi.Model() | ||
``` | ||
|
||
You need to install Gurobi separately from the [Gurobi website](https://www.gurobi.com/). After installing the software, you need to ensure the shared library of Gurobi is in the system path. | ||
|
||
- Windows: The `GUROBI_HOME` environment must be set to the Gurobi installation directory (like `C:\gurobi1100\win64`). The Gurobi shared library `gurobi110.dll` is located in the `bin` directory of the installation directory. The Gurobi installer usually sets this environment variable automatically, but you can also set it manually. | ||
|
||
- Linux: Add the Gurobi shared library to the `LD_LIBRARY_PATH` environment variable. The shared library `libgurobi110.so` is located in the `lib` directory of the installation directory. | ||
```bash | ||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gurobi1100/linux64/lib | ||
``` | ||
|
||
If you want to manage the license of Gurobi manually, you can create a `gurobi.Env` object and pass it to the constructor of the `gurobi.Model` object, otherwise we will initialize an implicit global `gurobi.Env` object automatically and use it. | ||
|
||
```python | ||
env = gurobi.Env() | ||
|
||
model = gurobi.Model(env) | ||
``` | ||
|
||
For example, you can set the parameter of the `gurobi.Env` object to choose the licensing behavior. | ||
|
||
```python | ||
env = gurobi.Env(empty=True) | ||
env.set_raw_parameter_string("ComputeServer", "myserver1:32123") | ||
env.set_raw_parameter_string("ServerPassword", "pass") | ||
env.start() | ||
|
||
model = gurobi.Model(env) | ||
``` | ||
|
||
## The capability of `gurobi.Model` | ||
|
||
### Supported constraints | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Constraint | ||
- Supported | ||
* - <project:#model.add_linear_constraint> | ||
- ✅ | ||
* - <project:#model.add_quadratic_constraint> | ||
- ✅ | ||
* - <project:#model.add_second_order_cone_constraint> | ||
- ✅ | ||
* - <project:#model.add_sos_constraint> | ||
- ✅ | ||
|
||
::: | ||
|
||
### Supported [model attribute](#pyoptinterface.ModelAttribute) | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Attribute | ||
- Get | ||
- Set | ||
* - Name | ||
- ✅ | ||
- ✅ | ||
* - ObjectiveSense | ||
- ✅ | ||
- ✅ | ||
* - DualStatus | ||
- ✅ | ||
- ❌ | ||
* - PrimalStatus | ||
- ✅ | ||
- ❌ | ||
* - RawStatusString | ||
- ✅ | ||
- ❌ | ||
* - TerminationStatus | ||
- ✅ | ||
- ❌ | ||
* - BarrierIterations | ||
- ✅ | ||
- ❌ | ||
* - DualObjectiveValue | ||
- ✅ | ||
- ❌ | ||
* - NodeCount | ||
- ✅ | ||
- ❌ | ||
* - NumberOfThreads | ||
- ✅ | ||
- ❌ | ||
* - ObjectiveBound | ||
- ❌ | ||
- ❌ | ||
* - ObjectiveValue | ||
- ✅ | ||
- ❌ | ||
* - RelativeGap | ||
- ✅ | ||
- ✅ | ||
* - Silent | ||
- ✅ | ||
- ✅ | ||
* - SimplexIterations | ||
- ✅ | ||
- ❌ | ||
* - SolverName | ||
- ✅ | ||
- ❌ | ||
* - SolverVersion | ||
- ✅ | ||
- ❌ | ||
* - SolveTimeSec | ||
- ✅ | ||
- ❌ | ||
* - TimeLimitSec | ||
- ✅ | ||
- ✅ | ||
|
||
::: | ||
|
||
### Supported [variable attribute](#pyoptinterface.VariableAttribute) | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Attribute | ||
- Get | ||
- Set | ||
* - Name | ||
- ✅ | ||
- ✅ | ||
* - LowerBound | ||
- ✅ | ||
- ✅ | ||
* - UpperBound | ||
- ✅ | ||
- ✅ | ||
* - Domain | ||
- ✅ | ||
- ✅ | ||
* - PrimalStart | ||
- ✅ | ||
- ✅ | ||
* - Value | ||
- ✅ | ||
- ❌ | ||
|
||
::: | ||
|
||
### Supported [constraint attribute](#pyoptinterface.ConstraintAttribute) | ||
|
||
:::{list-table} | ||
:header-rows: 1 | ||
|
||
* - Attribute | ||
- Get | ||
- Set | ||
* - Name | ||
- ✅ | ||
- ✅ | ||
* - Primal | ||
- ✅ | ||
- ❌ | ||
* - Dual | ||
- ✅ | ||
- ❌ | ||
|
||
::: | ||
|
||
|
||
## Solver-specific operations | ||
|
||
### Parameter | ||
|
||
For [solver-specific parameters](https://www.gurobi.com/documentation/current/refman/parameters.html#sec:Parameters), we provide `get_raw_parameter` and `set_raw_parameter` methods to get and set the parameters. | ||
|
||
```python | ||
model = gurobi.Model() | ||
|
||
# get the value of the parameter | ||
value = model.get_raw_parameter("TimeLimit") | ||
|
||
# set the value of the parameter | ||
model.set_raw_parameter("TimeLimit", 10.0) | ||
``` | ||
|
||
### Attribute | ||
|
||
Gurobi supports a lot of [attributes](https://www.gurobi.com/documentation/current/refman/attributes.html#sec:Attributes) for the model, variable, and constraint. We provide methods to get or set the value of the attribute. | ||
|
||
- Model attribute: `model.get_model_raw_attribute(name: str)` and `model.set_model_raw_attribute(name: str, value: Any)` | ||
- Variable attribute: `model.get_variable_raw_attribute(variable, name: str)` and `model.set_variable_raw_attribute(variable, name: str, value: Any)` | ||
- Constraint attribute: `model.get_constraint_raw_attribute(constraint, name: str)` and `model.set_constraint_raw_attribute(constraint, name: str, value: Any)` |
Oops, something went wrong.