Skip to content

Instantly share code, notes, and snippets.

@WillianFuks
Created November 19, 2021 21:44
Show Gist options
  • Save WillianFuks/74b53c31535ddada79a7ff645b72d9b1 to your computer and use it in GitHub Desktop.
Save WillianFuks/74b53c31535ddada79a7ff645b72d9b1 to your computer and use it in GitHub Desktop.
@pytest.mark.django_db
def test_data_2():
"""
Force overbooking of ships.
"""
name = 'test2'
f = Files.objects.create(name=name)
f.save()
demand_data = [
Demand(
name=f,
branch='B0',
destination='DESTINATION 0',
value=10
),
Demand(
name=f,
branch='B0',
destination='DESTINATION 0',
value=20
),
Demand(
name=f,
branch='B0',
destination='DESTINATION 0',
value=30
)
]
Demand.objects.bulk_create(demand_data)
freight_data = [
Freight(
name=f,
branch_origin='B0',
trade='TRADE 0',
destination_port='DESTINATION 0',
shipper='SHIPPER 0',
modal='MODAL 0',
transportation='TRANSPORTATION 0',
departure_port='PORT 0',
road_fees=3,
port_fees=4
),
Freight(
name=f,
branch_origin='B0',
trade='TRADE 0',
destination_port='DESTINATION 0',
shipper='SHIPPER 1',
modal='MODAL 0',
transportation='TRANSPORTATION 0',
departure_port='PORT 0',
road_fees=1,
port_fees=2
)
]
Freight.objects.bulk_create(freight_data)
shippers_data = [
Shippers(
name=f,
trade='TRADE 0',
shipper='SHIPPER 0',
slots=1
),
Shippers(
name=f,
trade='TRADE 0',
shipper='SHIPPER 1',
slots=1
)
]
Shippers.objects.bulk_create(shippers_data)
results = prepare_optimizer_data(name)
best_X = optimize(results, 3)
np.testing.assert_equal(best_X['x_shippers'], [[0, 1], [0, 0], [1, 0]])
np.testing.assert_equal(best_X['x_ob_shippers'], [[0, 0], [0, 1], [0, 0]])
np.testing.assert_equal(best_X['x_origins'], [[1], [1], [1]])
np.testing.assert_equal(best_X['x_transp'], [[1], [1], [1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment