LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
DecisionVariable.m
1classdef DecisionVariable < handle
2 % DecisionVariable Abstract base for line-opt decision variables. Mirrors
3 % native-Python line_solver.opt.variables.DecisionVariable: each variable
4 % encodes a tunable model parameter as continuous values in [0,1]
5 % (getBounds), decodes them to the native domain (decode), and applies the
6 % decoded value to a per-evaluation model copy (apply). Objects are
7 % re-resolved by name in the target model because models are copied per
8 % evaluation.
9
10 properties
11 name
12 dimension = 1;
13 end
14
15 methods
16 function obj = DecisionVariable(name)
17 obj.name = name;
18 end
19 function n = getName(obj)
20 n = obj.name;
21 end
22 function d = getDimension(obj)
23 d = obj.dimension;
24 end
25
26 function layers = getLayer(~, ~)
27 % LQN layer name(s) this variable perturbs, or {} for flat models.
28 % Consumed by layer freezing (explicit frozenLayers and adaptive
29 % auto-freeze): a variable whose layer set intersects the frozen
30 % set is held fixed. LQN variable subclasses override this.
31 layers = {};
32 end
33
34 function v = currentValue(~, ~)
35 % The variable's current (decoded) value in the given model, or []
36 % when not introspectable. Used by layer freezing to hold a
37 % variable at the model's existing parameter value. LQN variable
38 % subclasses override this.
39 v = [];
40 end
41 end
42
43 methods (Abstract)
44 b = getBounds(obj) % dimension x 2
45 v = decode(obj, x) % x is 1 x dimension in [0,1]
46 apply(obj, model, value)
47 t = getVariableType(obj)
48 end
49
50 methods (Static)
51 function c = resolveClass(model, jobclass)
52 c = [];
53 target = jobclass.getName();
54 classes = model.getClasses();
55 for i = 1:numel(classes)
56 if strcmp(classes{i}.getName(), target)
57 c = classes{i};
58 return;
59 end
60 end
61 end
62
63 function nd = resolveNode(model, node)
64 nd = [];
65 target = node.getName();
66 nodes = model.getNodes();
67 for i = 1:numel(nodes)
68 if strcmp(nodes{i}.getName(), target)
69 nd = nodes{i};
70 return;
71 end
72 end
73 end
74
75 function conn = connectionMatrix(model)
76 sn = model.getStruct();
77 conn = full(sn.connmatrix);
78 end
79
80 function b = unitBounds(dim)
81 b = [zeros(dim, 1), ones(dim, 1)];
82 end
83
84 function idx = indexOfNode(nodes, nameToFind)
85 idx = -1;
86 for i = 1:numel(nodes)
87 if strcmp(nodes{i}.getName(), nameToFind)
88 idx = i;
89 return;
90 end
91 end
92 end
93 end
94end
Definition fjtag.m:161