Opvious Python SDK
Project description
Opvious Python SDK
An optimization SDK for solving linear, mixed-integer, and quadratic models
import opvious
import opvious.modeling as om
class BinPacking(om.Model):
items = om.Dimension()
weight = om.Parameter.non_negative(items)
bins = om.interval(1, om.size(items))
bin_max_weight = om.Parameter.non_negative()
assigned = om.Variable.indicator(items, bins)
bin_used = om.Variable.indicator(bins)
@om.objective
def minimize_bins_used(self):
return om.total(self.bin_used(b) for b in self.bins)
@om.constraint
def each_item_is_assigned_once(self):
for i in self.items:
yield om.total(self.assigned(i, b) for b in self.bins) == 1
@om.constraint
def bins_with_assignments_are_used(self):
for i, b in om.cross(self.items, self.bins):
yield self.assigned(i, b) <= self.bin_used(b)
@om.constraint
def bin_weights_are_below_max(self):
for b in self.bins:
bin_weight = om.total(self.weight(i) * self.assigned(i, b) for i in self.items)
yield bin_weight <= self.bin_max_weight()
client = opvious.Client.from_environment()
response = await client.run_solve(
specification=BinPacking().specification(),
parameters={
"weight": {"a": 10.5, "b": 22, "c": 48},
"binMaxWeight": 50,
},
)
solution = response.outputs.variable("assigned") # Optimal assignment dataframe
Take a look at https://opvious.readthedocs.io for the full documentation or these notebooks to see it 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.12.1rc1.tar.gz
(104.8 kB
view hashes)
Built Distribution
Close
Hashes for opvious-0.12.1rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2180b5ea2c081ee4f68a68854375a6766d6f635959c89f2f7841d6773bd7a91 |
|
MD5 | bf2d1d8bc3e3ca51fa0b576a74ea514e |
|
BLAKE2b-256 | b48dea354dc2758cc107f0ddc47d1869adc952ea0fdfa60f17be6c799fce7940 |