-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ms/gurobi-funcs
- Loading branch information
Showing
29 changed files
with
1,252 additions
and
179 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
*.pyc | ||
__pycache__/ | ||
build | ||
.vscode | ||
.venv | ||
.pytest_cache | ||
*.egg-info | ||
|
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,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"." | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
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
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
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,32 @@ | ||
# Quadratic Expressions | ||
|
||
Quadratic expressions work as you'd expect. Simply multiply two linear expression together (or square an expression with `**2`) and you'll get a quadratic. The quadratic can then be used in constraints or the objective. | ||
|
||
## Example | ||
|
||
### Maximize area of box | ||
Here's a short example that shows that a square maximizes the area of any box with a fixed perimeter. | ||
|
||
```python3 | ||
import pyoframe as pf | ||
model = pf.Model("max") | ||
model.w = pf.Variable(lb=0) | ||
model.h = pf.Variable(lb=0) | ||
model.limit_perimter = 2 * (model.w + model.h) <= 20 | ||
model.objective = model.w * model.h | ||
model.solve() | ||
print(f"It's a square: {model.w.solution==model.h.solution}") | ||
|
||
# Outputs: It's a square: True | ||
``` | ||
### Facility Location Problem | ||
|
||
See [examples/facility_location](../tests/examples/facility_location/). | ||
|
||
## Note for Pyoframe developers: Internal Representation of Quadratics | ||
|
||
Internally, Pyoframe's `Expression` object is used for both linear and quadratic expressions. When the dataframe within an `Expression` object (i.e. `Expression.data`) contains an additional column (named `__quadratic_variable_id`) we know that the expression is a quadratic. | ||
|
||
This extra column stores the ID of the second variable in quadratic terms. For terms with only one variable, this column contains ID `0` (a reserved variable ID which can thought of as meaning 'no variable'). The variables in a quadratic are rearranged such that the ID in the `__variable_id` column is always greater or equal than the variable ID in the `__quadratic_variable_id` (recall: a*b=b*a). This rearranging not only ensures that a*b+b*a=2a*b but also generates a useful property: If the variable ID in the first column (`__variable_id`) is `0` we know the variable ID in the second must also be `0` and therefore the term must be a constant. | ||
|
||
The additional quadratic variable ID column is automatically dropped if through arithmetic the quadratic terms cancel out. |
File renamed without changes.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- [Pyoframe datastructure](./01_pyoframe-datastructure.md) | ||
- [Performance](./02_performance_tips.md) | ||
- [Troubleshooting](./03_troubleshooting.md) | ||
- [Quadratics](./03_quadratic_expressions.md) | ||
- [Troubleshooting](./04_troubleshooting) |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" | |
|
||
[project] | ||
name = "pyoframe" | ||
version = "0.0.11" | ||
version = "0.1.0" | ||
authors = [{ name = "Bravos Power", email = "[email protected]" }] | ||
description = "Blazing fast linear program interface" | ||
readme = "README.md" | ||
|
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
Oops, something went wrong.