Operational Research

# variables: x, y
# Objective: maximize 3x + 2y
# Constraints:
x >= 0
y >= 3
2x + y < 100
different types of operational research problems
Different Types of Operational Research Problems
from ortools.linear_solver import pywraplpsolver = pywraplp.Solver('test', pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)# variables, setting boundary
x = solver.NumVar(0, 100, 'x')
y = solver.NumVar(0, 100, 'y')
z = solver.NumVar(0, 100, 'z')
solver.NumVariables()# constraints
ct = solver.Constraint(0, 200, 'ct')
ct.SetCoefficient(x, 1)
ct.SetCoefficient(y, 1)
solver.NumConstraints()# objective
objective = solver.Objective()
objective.SetCoefficient(x, 1)
objective.SetCoefficient(y, 2)
objective.SetCoefficient(z, -3)
objective.SetMaximization()
print(f"number of variables: {solver.NumVariables()}")
print(f"number of constraints: {solver.NumConstraints()}")
status = solver.Solve()print(f"solved value: {objective.Value()}")print("x, y, z values:",
x.solution_value(),
y.solution_value(),
z.solution_value())

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store