1classdef OptimizationProblem < handle
2 % OptimizationProblem Declarative specification of a queueing-network
3 % optimization problem. Mirrors native-Python
4 % line_solver.opt.problem.OptimizationProblem.
8 variables = {}; % cell of opt.DecisionVariable
10 constraints = {}; % cell of opt.Constraint
11 fixedVariables = {}; % cell of {var, value}
12 scenarios = {}; % cell of {model, weight}
16 function obj = OptimizationProblem(model)
20 function m = getModel(obj), m = obj.model; end
21 function v = getVariables(obj), v = obj.variables; end
22 function o = getObjective(obj), o = obj.objective; end
23 function c = getConstraints(obj), c = obj.constraints; end
25 function obj = addVariable(obj, variable)
26 obj.variables{end+1} = variable;
28 function obj = setObjective(obj, objective)
29 obj.objective = objective;
31 function obj = addConstraint(obj, constraint)
32 obj.constraints{end+1} = constraint;
34 function obj = setFixedVariables(obj, pairs)
35 obj.fixedVariables = pairs;
37 function p = getFixedVariables(obj), p = obj.fixedVariables; end
38 function obj = addScenario(obj, scenarioModel, weight)
39 if nargin < 3, weight = 1.0; end
40 obj.scenarios{end+1} = {scenarioModel, weight};
42 function s = getScenarios(obj), s = obj.scenarios; end
44 function errors = validate(obj)
46 if isempty(obj.model), errors{end+1} =
'Model is not set'; end
47 if isempty(obj.variables), errors{end+1} =
'No decision variables defined'; end
48 if isempty(obj.objective), errors{end+1} =
'Objective function is not set'; end
51 function tf = isValid(obj)
52 tf = isempty(obj.validate());
55 function result = solve(obj, options)
56 errors = obj.validate();
58 line_error(mfilename, [
'Invalid problem: ' strjoin(errors,
', ')]);
60 if nargin < 2 || isempty(options)
61 options = opt.LineOptSolverOptions();
63 solver = opt.LineOptSolver(obj, options);
64 result = solver.solve();
67 function workflow = decompose(obj)
68 workflow = opt.DecompositionWorkflow(obj);