← All examples
59

Canonical Grid model

Applied mathematics - Resource allocation

Divisible production with two capacity limits and a capacity-change scenario.

Scale
Small
Source
applied-math-production.grid
Length
24 lines
Collection
Advanced language
Level
Intermediate
Runtime
Portable
applied-math-production.grid
Get Grid
MODEL "Applied mathematics - Resource allocation"
DESCRIPTION "Divisible production with two capacity limits and a capacity-change scenario."
TAGS "applied-mathematics", "optimization", "scenarios"

# Inputs: capacity and contribution per unit use consistent arbitrary units.
input ResourceCapacity = 100
  VALIDATE BETWEEN 0 AND 10000
input SecondCapacity = 80
  VALIDATE BETWEEN 0 AND 10000

# Solve once; projections reuse the same report.
output Report = LINEAR_PROGRAM.REPORT([5,4], [2,1;1,2], [ResourceCapacity,SecondCapacity], TRUE, ["Product X","Product Y"], ["Resource one","Resource two"])
output Production = Report.parameters
ProductX = INDEX(Production,1,1)
ProductY = INDEX(Production,1,2)

# Outputs: compare feasibility and contribution before interpreting marginals.
output Profit = Report.objective
output ResourceSlack = ResourceCapacity - 2 * ProductX - ProductY
output SecondSlack = SecondCapacity - ProductX - 2 * ProductY
output Verified = AND(ProductX >= -1e-9, ProductY >= -1e-9, ResourceSlack >= -1e-9, SecondSlack >= -1e-9, ABS(Profit - 5 * ProductX - 4 * ProductY) < 1e-8)
output Interpretation = "Products are divisible. Marginal resource values apply locally while the active constraints remain appropriate; re-solve each scenario."

END MODEL