production.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import numpy as np
  2. import cvxpy as cp
  3. class PowerSupply:
  4. def __init__(self):
  5. pass
  6. def power(self):
  7. pass
  8. class IntermittentArray(PowerSupply):
  9. def __init__(self,
  10. potential: np.ndarray,
  11. units_per_region: np.ndarray
  12. ):
  13. self.potential = potential
  14. self.units_per_region = units_per_region
  15. def power(self):
  16. return np.einsum('ijk,ik', self.potential, self.units_per_region)
  17. class DispatchableArray(PowerSupply):
  18. def __init__(self,
  19. dispatchable: np.ndarray
  20. ):
  21. self.dispatchable = np.array(dispatchable)
  22. self.n_dispatchable_sources = self.dispatchable.shape[0]
  23. def power(self, gap: np.ndarray) -> np.ndarray:
  24. # optimize dispatch
  25. T = len(gap)
  26. dispatch_power = cp.Variable((self.n_dispatchable_sources, T))
  27. constraints = [
  28. dispatch_power >= 0,
  29. cp.sum(dispatch_power, axis=0) <= np.maximum(gap, 0)
  30. ] + [
  31. dispatch_power[i,:] <= self.dispatchable[i,0]
  32. for i in range(self.n_dispatchable_sources)
  33. ] + [
  34. cp.sum(dispatch_power[i]) <= self.dispatchable[i,1]*T/(365.25*24)
  35. for i in range(self.n_dispatchable_sources)
  36. ]
  37. prob = cp.Problem(
  38. cp.Minimize(
  39. cp.sum(cp.pos(gap-cp.sum(dispatch_power, axis=0)))
  40. ),
  41. constraints
  42. )
  43. prob.solve(solver=cp.ECOS, max_iters=300)
  44. dp = dispatch_power.value
  45. return dp