Advertisement
Korotkodul

Задача 1. Оптимальное распределение ресурсов

Mar 1st, 2025 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import numpy as np
  2.  
  3. def can_satisfy_demand(
  4.     costs: np.ndarray,
  5.     resource_amounts: np.ndarray,
  6.     demand_expected: np.ndarray,
  7. ) -> bool:
  8.     print("costs")
  9.     print(costs)
  10.     print("resource_amounts")
  11.     print(resource_amounts)
  12.     print("demand_expected")
  13.     print(demand_expected)
  14.  
  15.     part1 = demand_expected[np.newaxis, :]
  16.     part2 = part1 * costs
  17.     part3 = np.sum(part2, axis = -1)
  18.     mask = (resource_amounts - part3) >= 0
  19.     print("part1")
  20.     print(part1)
  21.     print("part2")
  22.     print(part2)
  23.     print("part3")
  24.     print(part3)
  25.     print("mask")
  26.     print(mask)
  27.     print()
  28.     return not (False in mask)
  29.  
  30.  
  31. #costs = np.random.randint(1, 10, size=(3, 3))
  32. costs = np.eye(2)
  33. resource_amounts = np.full(shape=2, fill_value=3)
  34. demand_expected = np.full(shape=2, fill_value=2)
  35.  
  36. assert can_satisfy_demand(costs, resource_amounts, demand_expected)
  37. assert not can_satisfy_demand(costs, demand_expected, resource_amounts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement