A constraint function expresses a feasibility restriction on decision variables. In optimization, it limits which candidate values are allowed, while a solver evaluates the objective and constraint functions for proposed decisions. section 1.4.3 section 2.1.3
For event ticket sales, let x represent physical tickets and y virtual tickets. The constraint x + y ≤ 10,000 prevents combined sales from exceeding venue capacity, turning profit maximization into a constrained optimization problem. section 2.1.3
Ticket allocation with a Lagrangian
The constraint can be written as g(x,y) = x + y − 10,000. A Lagrangian combines the profit function and g with a multiplier, then solves the resulting derivative equations. The reported optimum allocates 6,424 physical tickets and 3,576 virtual tickets. 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])
The Python listing encodes the constraint, constructs the Lagrangian, differentiates it, and solves for the decision variables and multiplier. section 2.1.3

