LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Objective.m
1classdef Objective < handle
2 % Objective Abstract base for line-opt objectives. Mirrors native-Python
3 % line_solver.opt.objectives.Objective: defines the scalar to minimize,
4 % with attached constraints folded in as penalties by evaluateWithPenalty.
5
6 properties
7 constraints = {}; % cell array of opt.Constraint
8 end
9
10 methods
11 function c = getConstraints(obj)
12 c = obj.constraints;
13 end
14 function v = evaluateWithPenalty(obj, result, variableValues, penaltyWeight)
15 if nargin < 4, penaltyWeight = 1e6; end
16 v = obj.evaluate(result, variableValues);
17 for i = 1:numel(obj.constraints)
18 v = v + obj.constraints{i}.evaluate(result, variableValues) * penaltyWeight;
19 end
20 end
21 end
22
23 methods (Abstract)
24 v = evaluate(obj, result, variableValues)
25 tf = isMinimization(obj)
26 end
27
28 methods (Static)
29 function d = numericValue(value)
30 if isempty(value)
31 d = 0.0;
32 elseif isnumeric(value)
33 d = sum(value(:));
34 else
35 d = 0.0;
36 end
37 end
38 function tf = isScalarNumeric(value)
39 tf = isnumeric(value) && isscalar(value);
40 end
41 end
42end
Definition Station.m:245