LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
OptimizationProblem.m
1classdef OptimizationProblem < handle
2 % OptimizationProblem Declarative specification of a queueing-network
3 % optimization problem. Mirrors native-Python
4 % line_solver.opt.problem.OptimizationProblem.
5
6 properties
7 model
8 variables = {}; % cell of opt.DecisionVariable
9 objective = [];
10 constraints = {}; % cell of opt.Constraint
11 fixedVariables = {}; % cell of {var, value}
12 scenarios = {}; % cell of {model, weight}
13 end
14
15 methods
16 function obj = OptimizationProblem(model)
17 obj.model = model;
18 end
19
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
24
25 function obj = addVariable(obj, variable)
26 obj.variables{end+1} = variable;
27 end
28 function obj = setObjective(obj, objective)
29 obj.objective = objective;
30 end
31 function obj = addConstraint(obj, constraint)
32 obj.constraints{end+1} = constraint;
33 end
34 function obj = setFixedVariables(obj, pairs)
35 obj.fixedVariables = pairs;
36 end
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};
41 end
42 function s = getScenarios(obj), s = obj.scenarios; end
43
44 function errors = validate(obj)
45 errors = {};
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
49 end
50
51 function tf = isValid(obj)
52 tf = isempty(obj.validate());
53 end
54
55 function result = solve(obj, options)
56 errors = obj.validate();
57 if ~isempty(errors)
58 line_error(mfilename, ['Invalid problem: ' strjoin(errors, ', ')]);
59 end
60 if nargin < 2 || isempty(options)
61 options = opt.LineOptSolverOptions();
62 end
63 solver = opt.LineOptSolver(obj, options);
64 result = solver.solve();
65 end
66
67 function workflow = decompose(obj)
68 workflow = opt.DecompositionWorkflow(obj);
69 end
70 end
71end