An equality constraint requires an expression involving decision variables to equal a specified value exactly. It narrows the feasible search space while the objective function identifies the preferred feasible solution. section 2.1.3 section 1.3
Ticket allocation
A conference has 10,000 physical welcome packages and must sell exactly 10,000 tickets across physical and virtual attendance. With x as physical sales and y as virtual sales, the equality is x + y = 10,000. Profit remains the objective, so the task is to find the most profitable allocation satisfying that exact total. section 2.1.3
Listing 2.5 Maximizing profits using Lagrange multipliers
import sympy as sym
x,y=sym.var('x, y', positive=True) #1
f=155*x+(0.001*x**sym.Rational(3,2)+70)*y-1000000 #2
g=x+y-10000 #3
lamda=sym.symbols('lambda') #4
Lagr=f-lamda*g #5
eqs = [sym.diff(Lagr, x), sym.diff(Lagr, y), g] #6
sol=sym.solve(eqs,[x,y,lamda], dict=True) #7
def getValueOf(k, L):
for d in L:
if k in d:
return d[k]
profit=[f.subs(p) for p in sol]
print("optimal number of physical ticket sales: x = %.0f" % getValueOf(x, sol))
print("optimal number of online ticket sales: y = %.0f" % getValueOf(y, sol))
print("Expected profil: f(x,y) = $%.4f" % profit[0])
A SymPy implementation represents the equality as g = x + y − 10000, forms a Lagrangian, differentiates with respect to x, y, and the multiplier, and solves the resulting equations. section 2.1.3
