Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def can_satisfy_demand(
- costs: np.ndarray,
- resource_amounts: np.ndarray,
- demand_expected: np.ndarray,
- ) -> bool:
- print("costs")
- print(costs)
- print("resource_amounts")
- print(resource_amounts)
- print("demand_expected")
- print(demand_expected)
- part1 = demand_expected[np.newaxis, :]
- part2 = part1 * costs
- part3 = np.sum(part2, axis = -1)
- mask = (resource_amounts - part3) >= 0
- print("part1")
- print(part1)
- print("part2")
- print(part2)
- print("part3")
- print(part3)
- print("mask")
- print(mask)
- print()
- return not (False in mask)
- #costs = np.random.randint(1, 10, size=(3, 3))
- costs = np.eye(2)
- resource_amounts = np.full(shape=2, fill_value=3)
- demand_expected = np.full(shape=2, fill_value=2)
- assert can_satisfy_demand(costs, resource_amounts, demand_expected)
- assert not can_satisfy_demand(costs, demand_expected, resource_amounts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement