Opvious Python SDK
Project description
Opvious Python SDK
![Pypi badge](https://pypi-camo.freetls.fastly.net/dc506e98b1d565d7461b38a4af381a403b26c1de/68747470733a2f2f62616467652e667572792e696f2f70792f6f7076696f75732e737667)
An SDK for solving linear, mixed-integer, and quadratic optimization models via the Opvious API.
Highlights
Declarative modeling API
- Extensive static validations
- Exportable to LaTeX
- Extensible support for high-level patterns (activation variables, masks, ...)
import opvious.modeling as om
class BinPacking(om.Model):
items = om.Dimension() # All items to bin
weight = om.Parameter.non_negative(items) # Weight per item
bins = om.interval(1, om.size(items), name="B") # Available bins
max_weight = om.Parameter.non_negative() # Maximum weight for each bin
assigned = om.Variable.indicator(bins, items) # Bin to item assignment
used = om.fragments.ActivationVariable(assigned, projection=1) # 1 if a bin is used
@om.constraint
def each_item_is_assigned_once(self):
for i in self.items:
yield om.total(self.assigned(b, i) for b in self.bins) == 1
@om.constraint
def bin_weights_are_below_max(self):
for b in self.bins:
bin_weight = om.total(self.weight(i) * self.assigned(b, i) for i in self.items)
yield bin_weight <= self.max_weight()
@om.objective
def minimize_bins_used(self):
return om.total(self.used(b) for b in self.bins)
Auto-generated specification:
Transparent remote solves
- No local solver installation required
- Real-time progress notifications
- Seamless data import/export via native support for
pandas
- Flexible multi-objective support: weighted sums, epsilon constraints, ...
- Built-in debugging capabilities: relaxations, fully annotated LP formatting, ...
import opvious
client = opvious.Client.default()
solution = await client.solve(
opvious.Problem(
specification=BinPacking().specification(),
parameters={
"weight": {"a": 10.5, "b": 22, "c": 48},
"binMaxWeight": 50,
},
),
)
assignments = solution.outputs.variable("assigned") # Optimal values
Take a look at https://opvious.readthedocs.io for the full documentation or these notebooks to see the SDK in action.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
opvious-0.17.1rc1.tar.gz
(121.8 kB
view hashes)
Built Distribution
Close
Hashes for opvious-0.17.1rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82e86a6a91e5f28741285444609b36c8310a4a1ed8189fa8a5b3bdbeb8dec370 |
|
MD5 | 424c080571a2c6ef2ea58e99539eef84 |
|
BLAKE2b-256 | bdfd6a9a3f6f6253ed5f2f547300cb4487daf101e6e074c1127f028aeec4a876 |