linny-r 1.4.3 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -48
- package/package.json +1 -1
- package/server.js +31 -6
- package/static/images/check-off-not-same-changed.png +0 -0
- package/static/images/check-off-not-same-not-changed.png +0 -0
- package/static/images/check-off-same-changed.png +0 -0
- package/static/images/check-off-same-not-changed.png +0 -0
- package/static/images/check-on-not-same-changed.png +0 -0
- package/static/images/check-on-not-same-not-changed.png +0 -0
- package/static/images/check-on-same-changed.png +0 -0
- package/static/images/check-on-same-not-changed.png +0 -0
- package/static/images/eq-not-same-changed.png +0 -0
- package/static/images/eq-not-same-not-changed.png +0 -0
- package/static/images/eq-same-changed.png +0 -0
- package/static/images/eq-same-not-changed.png +0 -0
- package/static/images/ne-not-same-changed.png +0 -0
- package/static/images/ne-not-same-not-changed.png +0 -0
- package/static/images/ne-same-changed.png +0 -0
- package/static/images/ne-same-not-changed.png +0 -0
- package/static/images/sort-asc-lead.png +0 -0
- package/static/images/sort-asc.png +0 -0
- package/static/images/sort-desc-lead.png +0 -0
- package/static/images/sort-desc.png +0 -0
- package/static/images/sort-not.png +0 -0
- package/static/index.html +51 -35
- package/static/linny-r.css +167 -53
- package/static/scripts/linny-r-gui-actor-manager.js +340 -0
- package/static/scripts/linny-r-gui-chart-manager.js +944 -0
- package/static/scripts/linny-r-gui-constraint-editor.js +681 -0
- package/static/scripts/linny-r-gui-controller.js +4005 -0
- package/static/scripts/linny-r-gui-dataset-manager.js +1176 -0
- package/static/scripts/linny-r-gui-documentation-manager.js +739 -0
- package/static/scripts/linny-r-gui-equation-manager.js +307 -0
- package/static/scripts/linny-r-gui-experiment-manager.js +1944 -0
- package/static/scripts/linny-r-gui-expression-editor.js +450 -0
- package/static/scripts/linny-r-gui-file-manager.js +392 -0
- package/static/scripts/linny-r-gui-finder.js +727 -0
- package/static/scripts/linny-r-gui-model-autosaver.js +230 -0
- package/static/scripts/linny-r-gui-monitor.js +448 -0
- package/static/scripts/linny-r-gui-paper.js +2789 -0
- package/static/scripts/linny-r-gui-receiver.js +323 -0
- package/static/scripts/linny-r-gui-repository-browser.js +819 -0
- package/static/scripts/linny-r-gui-scale-unit-manager.js +244 -0
- package/static/scripts/linny-r-gui-sensitivity-analysis.js +778 -0
- package/static/scripts/linny-r-gui-undo-redo.js +560 -0
- package/static/scripts/linny-r-model.js +34 -15
- package/static/scripts/linny-r-utils.js +11 -1
- package/static/scripts/linny-r-vm.js +21 -12
- package/static/scripts/linny-r-gui.js +0 -16908
@@ -0,0 +1,340 @@
|
|
1
|
+
/*
|
2
|
+
Linny-R is an executable graphical specification language for (mixed integer)
|
3
|
+
linear programming (MILP) problems, especially unit commitment problems (UCP).
|
4
|
+
The Linny-R language and tool have been developed by Pieter Bots at Delft
|
5
|
+
University of Technology, starting in 2009. The project to develop a browser-
|
6
|
+
based version started in 2017. See https://linny-r.org for more information.
|
7
|
+
|
8
|
+
This JavaScript file (linny-r-gui-actor-manager.js) provides the GUI
|
9
|
+
functionality for the Linny-R Actor Manager dialog.
|
10
|
+
|
11
|
+
*/
|
12
|
+
|
13
|
+
/*
|
14
|
+
Copyright (c) 2017-2023 Delft University of Technology
|
15
|
+
|
16
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
17
|
+
of this software and associated documentation files (the "Software"), to deal
|
18
|
+
in the Software without restriction, including without limitation the rights to
|
19
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
20
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
21
|
+
so, subject to the following conditions:
|
22
|
+
|
23
|
+
The above copyright notice and this permission notice shall be included in
|
24
|
+
all copies or substantial portions of the Software.
|
25
|
+
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
27
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
28
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
29
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
30
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
31
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
32
|
+
SOFTWARE.
|
33
|
+
*/
|
34
|
+
|
35
|
+
// CLASS ActorManager (modal dialog!)
|
36
|
+
class ActorManager {
|
37
|
+
constructor() {
|
38
|
+
// Make the Actors modal buttons responsive
|
39
|
+
UI.modals.actors.ok.addEventListener(
|
40
|
+
'click', () => ACTOR_MANAGER.updateActorProperties());
|
41
|
+
UI.modals.actors.cancel.addEventListener(
|
42
|
+
'click', () => UI.modals.actors.hide());
|
43
|
+
this.dialog = document.getElementById('actors-dlg');
|
44
|
+
this.round_count = document.getElementById('round-count');
|
45
|
+
this.add_btn = document.getElementById('add-round-btn');
|
46
|
+
this.add_btn.addEventListener(
|
47
|
+
'click', () => ACTOR_MANAGER.addRound());
|
48
|
+
this.delete_btn = document.getElementById('delete-round-btn');
|
49
|
+
this.delete_btn.addEventListener(
|
50
|
+
'click', () => ACTOR_MANAGER.deleteSelectedRound());
|
51
|
+
this.sequence = document.getElementById('default-sequence');
|
52
|
+
this.scroll_area = document.getElementById('actors-scroll');
|
53
|
+
this.header = document.getElementById('rounds-hdr');
|
54
|
+
this.table = document.getElementById('actors-table');
|
55
|
+
// Modal related to this dialog
|
56
|
+
this.actor_modal = new ModalDialog('actor');
|
57
|
+
this.actor_modal.ok.addEventListener(
|
58
|
+
'click', () => ACTOR_MANAGER.modifyActorEntry());
|
59
|
+
this.actor_modal.cancel.addEventListener(
|
60
|
+
'click', () => ACTOR_MANAGER.actor_modal.hide());
|
61
|
+
this.actor_name = document.getElementById('actor-name');
|
62
|
+
this.actor_span = document.getElementById('actor-span');
|
63
|
+
this.actor_io = document.getElementById('actor-io');
|
64
|
+
this.actor_io.addEventListener(
|
65
|
+
'click', () => UI.toggleImportExportBox('actor'));
|
66
|
+
this.actor_weight = document.getElementById('actor-W');
|
67
|
+
document.getElementById('actor-W-x').addEventListener(
|
68
|
+
'click', (event) => X_EDIT.editExpression(event));
|
69
|
+
// Initialize properties
|
70
|
+
this.rounds = 1;
|
71
|
+
this.selected_round = 0;
|
72
|
+
}
|
73
|
+
|
74
|
+
roundLetter(n) {
|
75
|
+
// Returns integer `n` as lower case letter: 1 = a, 2 = b, 26 = z
|
76
|
+
// NOTE: numbers 27-52 return upper case A-Z; beyond ranges results in '?'
|
77
|
+
if(n < 1 || n > this.max_rounds) return '?';
|
78
|
+
return VM.round_letters[n];
|
79
|
+
}
|
80
|
+
|
81
|
+
checkRoundSequence(s) {
|
82
|
+
// Expects a string with zero or more round letters
|
83
|
+
for(let i = 0; i < s.length; i++) {
|
84
|
+
const n = VM.round_letters.indexOf(s[i]);
|
85
|
+
if(n < 1 || n > this.rounds) {
|
86
|
+
UI.warn(`Round ${s[i]} outside range (a` +
|
87
|
+
(this.rounds > 1 ? '-' + this.roundLetter(this.rounds) : '') + ')');
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
return s;
|
92
|
+
}
|
93
|
+
|
94
|
+
showDialog(reset=true) {
|
95
|
+
// Display the "actor list view" modal
|
96
|
+
let html = '';
|
97
|
+
// Create a sorted actor list with items [id, name, flags, weight, iotype]
|
98
|
+
// where flags is interpreted bitwise (bit N = 1 => checked for round N)
|
99
|
+
if(reset) {
|
100
|
+
// If reset, infer actor list and number of rounds from model
|
101
|
+
MODEL.cleanUpActors();
|
102
|
+
this.rounds = MODEL.rounds;
|
103
|
+
this.selected_round = 0;
|
104
|
+
}
|
105
|
+
this.round_count.innerHTML = pluralS(this.rounds, 'round');
|
106
|
+
if(this.rounds < VM.max_rounds) {
|
107
|
+
this.add_btn.classList.remove('v-disab');
|
108
|
+
} else {
|
109
|
+
this.add_btn.classList.add('v-disab');
|
110
|
+
}
|
111
|
+
if(this.rounds > 1) {
|
112
|
+
this.delete_btn.classList.remove('v-disab');
|
113
|
+
} else {
|
114
|
+
this.delete_btn.classList.add('v-disab');
|
115
|
+
}
|
116
|
+
this.sequence.placeholder =
|
117
|
+
VM.round_letters.slice(1, this.rounds + 1) + ' (default)';
|
118
|
+
this.sequence.value = MODEL.round_sequence;
|
119
|
+
const ioc = ['', ' import', ' export'];
|
120
|
+
for(let i = 0; i < MODEL.actor_list.length; i++) {
|
121
|
+
const
|
122
|
+
a = MODEL.actor_list[i],
|
123
|
+
bits = a[2],
|
124
|
+
rf = [];
|
125
|
+
let b = 1;
|
126
|
+
for(let r = 1; r <= this.rounds; r++) {
|
127
|
+
rf.push('<div id="a-box-', i, '-', r, '" class="abox ',
|
128
|
+
((bits & b) != 0 ? 'checked' : 'clear'), '"></div>');
|
129
|
+
b *= 2;
|
130
|
+
}
|
131
|
+
html += ['<tr class="actor" onmouseover="ACTOR_MANAGER.showActorInfo(',
|
132
|
+
i, ', event.shiftKey);"><td id="a-name-', i,
|
133
|
+
'" class="a-name', ioc[a[4]], '">', a[1], '</td><td id="a-weight-', i,
|
134
|
+
'" class="a-weight">', a[3], '</td><td class="a-box">', rf.join(''),
|
135
|
+
'</td></tr>'].join('');
|
136
|
+
}
|
137
|
+
const rows = Math.min(9, MODEL.actor_list.length - 1);
|
138
|
+
this.dialog.style.height = (103 + 23 * rows) + 'px';
|
139
|
+
this.dialog.style.width = (342 + (rows ? 18 : 0) + 22 * this.rounds) + 'px';
|
140
|
+
this.scroll_area.style.height = (24 + 23 * rows) + 'px';
|
141
|
+
this.scroll_area.style.overflowY = (rows ? 'scroll' : 'clip');
|
142
|
+
// Update column headers
|
143
|
+
const rch = [];
|
144
|
+
for(let r = 1; r <= this.rounds; r++) {
|
145
|
+
rch.push('<div id="round-', r, '" class="round-nr',
|
146
|
+
(r == this.selected_round ? ' sel' : ''),
|
147
|
+
'" onclick="ACTOR_MANAGER.toggleRound(', r, ', event.ctrlKey);">',
|
148
|
+
this.roundLetter(r), '</div>');
|
149
|
+
}
|
150
|
+
this.header.innerHTML = rch.join('');
|
151
|
+
this.table.innerHTML = html;
|
152
|
+
// Bind click event to newly created checkboxes
|
153
|
+
const
|
154
|
+
abs = this.table.getElementsByClassName('abox'),
|
155
|
+
abns = this.table.getElementsByClassName('a-name'),
|
156
|
+
abws = this.table.getElementsByClassName('a-weight'),
|
157
|
+
abf = (event) => UI.toggleBox(event),
|
158
|
+
eaf = (event) => {
|
159
|
+
// NOTE: The user has clicked on either cell 1 or cell 2 of a row
|
160
|
+
// in the actors table, but both need to be passed on.
|
161
|
+
const p = event.target.parentElement;
|
162
|
+
// Pass name and weight of the selected actor (first and second
|
163
|
+
// TD of this TR)
|
164
|
+
ACTOR_MANAGER.showEditActorDialog(
|
165
|
+
p.cells[0].innerText, p.cells[1].innerText);
|
166
|
+
};
|
167
|
+
for(let i = 0; i < abs.length; i++) {
|
168
|
+
abs[i].addEventListener('click', abf);
|
169
|
+
}
|
170
|
+
// Clicking the other cells should open the ACTOR dialog
|
171
|
+
for(let i = 0; i < abns.length; i++) {
|
172
|
+
abns[i].addEventListener('click', eaf);
|
173
|
+
}
|
174
|
+
for(let i = 0; i < abws.length; i++) {
|
175
|
+
abws[i].addEventListener('click', eaf);
|
176
|
+
}
|
177
|
+
UI.modals.actors.show();
|
178
|
+
}
|
179
|
+
|
180
|
+
updateRoundFlags() {
|
181
|
+
for(let i = 0; i < MODEL.actor_list.length; i++) {
|
182
|
+
let rf = 0, b = 1;
|
183
|
+
for(let r = 1; r <= this.rounds; r++) {
|
184
|
+
const abox = document.getElementById(`a-box-${i}-${r}`);
|
185
|
+
if(abox.classList.contains('checked')) rf += b;
|
186
|
+
b *= 2;
|
187
|
+
}
|
188
|
+
MODEL.actor_list[i][2] = rf;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
addRound() {
|
193
|
+
// Limit # rounds to 30 to cope with 32 bit integer used by JavaScript
|
194
|
+
if(this.rounds < VM.max_rounds) {
|
195
|
+
this.rounds++;
|
196
|
+
this.round_count.innerHTML = pluralS(this.rounds, 'round');
|
197
|
+
this.showDialog(false);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
deleteSelectedRound() {
|
202
|
+
if(this.selected_round > 0 && this.selected_round <= this.rounds) {
|
203
|
+
const mask = Math.pow(2, this.selected_round) - 1;
|
204
|
+
this.updateRoundFlags();
|
205
|
+
for(let i = 0; i < MODEL.actor_list.length; i++) {
|
206
|
+
let rf = MODEL.actor_list[i][2];
|
207
|
+
const
|
208
|
+
low = (rf & mask),
|
209
|
+
high = (rf & ~mask) >>> 1;
|
210
|
+
MODEL.actor_list[i][2] = (low | high);
|
211
|
+
}
|
212
|
+
this.rounds--;
|
213
|
+
this.selected_round = 0;
|
214
|
+
this.showDialog(false);
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
toggleRound(r, ctrl) {
|
219
|
+
if(ctrl) {
|
220
|
+
const check = !UI.boxChecked(`a-box-0-${r}`);
|
221
|
+
for(let i = 0; i < MODEL.actor_list.length; i++) {
|
222
|
+
UI.setBox(`a-box-${i}-${r}`, check);
|
223
|
+
}
|
224
|
+
} else {
|
225
|
+
const el = document.getElementById('round-' + this.selected_round);
|
226
|
+
if(el) el.classList.remove('sel');
|
227
|
+
this.selected_round = r;
|
228
|
+
document.getElementById('round-' + r).classList.add('sel');
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
showEditActorDialog(name, expr) {
|
233
|
+
// Display modal for editing properties of one actor
|
234
|
+
this.actor_span.innerHTML = name;
|
235
|
+
this.actor_name.value = name;
|
236
|
+
// Do not allow modification of the name '(no actor)'
|
237
|
+
if(name === UI.NO_ACTOR) {
|
238
|
+
this.actor_name.disabled = true;
|
239
|
+
this.actor_io.style.display = 'none';
|
240
|
+
} else {
|
241
|
+
this.actor_name.disabled = false;
|
242
|
+
UI.setImportExportBox('actor', MODEL.ioType(MODEL.objectByName(name)));
|
243
|
+
this.actor_io.style.display = 'block';
|
244
|
+
}
|
245
|
+
this.actor_weight.value = expr;
|
246
|
+
this.actor_modal.show();
|
247
|
+
}
|
248
|
+
|
249
|
+
modifyActorEntry() {
|
250
|
+
// This method is called when the modeler submits the "actor properties"
|
251
|
+
// dialog
|
252
|
+
let n = this.actor_span.innerHTML,
|
253
|
+
nn = UI.NO_ACTOR,
|
254
|
+
x = this.actor_weight.value.trim(),
|
255
|
+
xp = new ExpressionParser(x);
|
256
|
+
if(n !== UI.NO_ACTOR) {
|
257
|
+
nn = this.actor_name.value.trim();
|
258
|
+
// NOTE: prohibit colons in actor names to avoid confusion with
|
259
|
+
// prefixed entities
|
260
|
+
if(!UI.validName(nn) || nn.indexOf(':') >= 0) {
|
261
|
+
UI.warn(UI.WARNING.INVALID_ACTOR_NAME);
|
262
|
+
return false;
|
263
|
+
}
|
264
|
+
}
|
265
|
+
if(xp.error) {
|
266
|
+
// NOTE: do not pass the actor, as its name is being edited as well
|
267
|
+
UI.warningInvalidWeightExpression(null, xp.error);
|
268
|
+
return false;
|
269
|
+
}
|
270
|
+
for(let i = 0; i < MODEL.actor_list.length; i++) {
|
271
|
+
const a = MODEL.actor_list[i];
|
272
|
+
if(a[1] == n) {
|
273
|
+
// Always update the actors' `weight` and `import/export` properties...
|
274
|
+
a[3] = x;
|
275
|
+
a[4] = UI.getImportExportBox('actor');
|
276
|
+
// .. but the `name` property NOT for "(no actor)"
|
277
|
+
if(i !== 0) a[1] = nn;
|
278
|
+
document.getElementById('a-weight-' + i).innerHTML = x;
|
279
|
+
const td = document.getElementById('a-name-' + i);
|
280
|
+
td.innerHTML = nn;
|
281
|
+
td.classList.remove('import', 'export');
|
282
|
+
if(a[4] === 1) {
|
283
|
+
td.classList.add('import');
|
284
|
+
} else if(a[4] === 2) {
|
285
|
+
td.classList.add('export');
|
286
|
+
}
|
287
|
+
break;
|
288
|
+
}
|
289
|
+
}
|
290
|
+
this.actor_modal.hide();
|
291
|
+
}
|
292
|
+
|
293
|
+
updateActorProperties() {
|
294
|
+
// This method is called when the modeler clicks OK on the actor list dialog
|
295
|
+
this.updateRoundFlags();
|
296
|
+
const xp = new ExpressionParser('');
|
297
|
+
let a,
|
298
|
+
ali,
|
299
|
+
ok = true;
|
300
|
+
for(let i = 0; i < MODEL.actor_list.length; i++) {
|
301
|
+
ali = MODEL.actor_list[i];
|
302
|
+
a = MODEL.actors[ali[0]];
|
303
|
+
// Rename actor if name has been changed
|
304
|
+
if(a.displayName != ali[1]) a.rename(ali[1]);
|
305
|
+
// Set its round flags
|
306
|
+
a.round_flags = ali[2];
|
307
|
+
// Double-check: parse expression if weight has been changed
|
308
|
+
if(a.weight.text != ali[3]) {
|
309
|
+
xp.expr = ali[3];
|
310
|
+
xp.compile();
|
311
|
+
if(xp.error) {
|
312
|
+
UI.warningInvalidWeightExpression(a, xp.error);
|
313
|
+
ok = false;
|
314
|
+
} else {
|
315
|
+
a.weight.update(xp);
|
316
|
+
}
|
317
|
+
}
|
318
|
+
// Update import/export status
|
319
|
+
MODEL.ioUpdate(a, ali[4]);
|
320
|
+
}
|
321
|
+
const seq = this.sequence.value;
|
322
|
+
if(this.checkRoundSequence(seq) === false) ok = false;
|
323
|
+
if(ok) {
|
324
|
+
MODEL.round_sequence = seq;
|
325
|
+
MODEL.rounds = this.rounds;
|
326
|
+
UI.modals.actors.hide();
|
327
|
+
}
|
328
|
+
}
|
329
|
+
|
330
|
+
showActorInfo(n, shift) {
|
331
|
+
// Show actor documentation when Shift is held down
|
332
|
+
// NOTE: do not allow documentation of "(no actor)"
|
333
|
+
if(n > 0) {
|
334
|
+
const a = MODEL.actorByID(MODEL.actor_list[n][0]);
|
335
|
+
DOCUMENTATION_MANAGER.update(a, shift);
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
} // END of class ActorManager
|
340
|
+
|