Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overconstrained Error emerging from measure.cumulative_resource() #16

Open
elliott-huge opened this issue Mar 21, 2022 · 0 comments
Open

Comments

@elliott-huge
Copy link
Collaborator

elliott-huge commented Mar 21, 2022

Code to reproduce error:

from mat_dp_core import Resources, Processes, GeConstraint, LeConstraint, Measure

r = Resources()
iron_ore = r.create("Iron Ore", "metric tonnes")
iron = r.create("Iron", "metric tonnes")
coal = r.create("Coal", "metric tonnes")
carbon_dioxide = r.create("CO2", "metric tonnes")
steel = r.create("Steel", "metric tonnes")
rail = r.create("Steel Rail", "metres")
wagon = r.create("Railway Wagon", "units")

p = Processes()
coal_mine = p.create("Coal Mine", (carbon_dioxide, 0.2), (coal, 1.0))
iron_mine = p.create("Iron Ore Mine", (carbon_dioxide, 0.2), (iron_ore, 1.0))
iron_furnace = p.create("Iron Blast Furnace", (carbon_dioxide, 0.5), (iron, 1.0), (coal, -0.4), (iron_ore, -1.2))
steel_mill = p.create("Steel Mill", (carbon_dioxide, 0.7), (iron, -0.9), (coal, -0.5), (steel, 1.0))
rail_factory = p.create("Rail Manufacturing Factory", (carbon_dioxide, 0.1), (steel, -0.1), (rail, 1.0))
rail_wagon_factory = p.create("Wagon Manufacturing Factory", (carbon_dioxide, 0.3), (steel, -4.0), (wagon, 1.0))
environment = p.create("The Atmosphere", (carbon_dioxide, -1.0))

rail_buy = p.create("Economy demanding rail", (rail, -1))
wagon_buy = p.create("Economy demanding wagons", (wagon, -1))

# Constraints
rail_demand = GeConstraint("Demand for rail", rail_buy, 500)
wagon_demand = GeConstraint("Demand for wagons", wagon_buy, 5)

objective = environment

constraints = [rail_demand, wagon_demand]

measure = Measure(r, p, constraints, objective)

# .cumulative_resource()

# This example of cumulative_resource() is not yet operational
# See issue NUMBER_HERE for details.
print("---\n\n1) All cumulative resource flows from everything to everything:")
# print(measure.cumulative_resource()) # Option 1

print("---\n\n2) All cumulative resource flows from everything to the wagon factory:")
print(measure.cumulative_resource(process=rail_wagon_factory)) # Option 2

print("---\n\n3) Cumulative resource flows of iron from everything to everything::")
print(measure.cumulative_resource(resource=iron)) # Option 3

print("---\n\n4) Cumulative amount of CO2 leading up to all the production rail factory:")
print(measure.cumulative_resource(process=rail_factory, resource=carbon_dioxide)) # Option 4

Produces the following error:

PS ######\mat-dp-core\examples> poetry run python .\test.py
---

1) All cumulative resource flows from everything to everything:
---

2) All cumulative resource flows from everything to the wagon factory:
######\mat-dp-core\mat_dp_core\maths_core\solve.py:201: OptimizeWarning: A_eq does not appear to be of full row rank. To improve performance, check the problem formulation for redundant equality constraints.
  res = linprog(
Traceback (most recent call last):
  File "######\mat-dp-core\examples\test.py", line 255, in <module>
    print(measure.cumulative_resource(process=rail_wagon_factory)) # Option 2
  File "######\mat-dp-core\mat_dp_core\measure.py", line 758, in cumulative_resource
    self.cumulative_resource_matrix[:, process.index],
  File "######\mat-dp-core\mat_dp_core\maths_core\solvers.py", line 386, in cumulative_resource_matrix
    self._exact_solver.cumulative_resource_matrix
  File "######\mat-dp-core\mat_dp_core\maths_core\solvers.py", line 214, in cumulative_resource_matrix
    construct_cumulative_resource_matrix(
  File "######\mat-dp-core\mat_dp_core\maths_core\solvers.py", line 134, in construct_cumulative_resource_matrix
    [
  File "######\mat-dp-core\mat_dp_core\maths_core\solvers.py", line 135, in <listcomp>
    solve(
  File "######\mat-dp-core\mat_dp_core\maths_core\solve.py", line 237, in solve
    raise Overconstrained.from_vector(
mat_dp_core.maths_core.exceptions.Overconstrained: Overconstrained problem:
resources:
Coal => 60.200000007230194: increase runs of Iron Blast Furnace, Steel Mill or decrease runs of Coal Mine
CO2 => 12.040000001446039: increase runs of The Atmosphere or decrease runs of Coal Mine, Iron Ore Mine, Iron Blast Furnace, Steel Mill, Rail Manufacturing Factory, Wagon Manufacturing Factory
eq_constraints:
Coal Mine - 1.255813953488226*Iron Ore Mine == 0 => -60.200000007230194
Coal Mine - 1.0465116279069493*Iron Blast Furnace == 0 => -60.200000007230194
Coal Mine - 1.1627906976743299*Steel Mill == 0 => -60.200000007230194
Coal Mine - 8.305647840271908*Rail Manufacturing Factory == 0 => -60.200000007230194
Coal Mine - 0.0830564784122155*Wagon Manufacturing Factory == 0 => -60.200000007230194
PS ######\mat-dp-core\examples>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant