linny-r 1.4.3 → 1.4.4
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 +449 -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 +24 -11
- package/static/scripts/linny-r-utils.js +10 -0
- package/static/scripts/linny-r-vm.js +21 -12
- package/static/scripts/linny-r-gui.js +0 -16908
@@ -0,0 +1,307 @@
|
|
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-eqmgr.js) provides the GUI functionality
|
9
|
+
for the Linny-R Equation 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 EquationManager provides the equation dialog functionality
|
36
|
+
class EquationManager {
|
37
|
+
constructor() {
|
38
|
+
this.dialog = UI.draggableDialog('equation');
|
39
|
+
UI.resizableDialog('equation', 'EQUATION_MANAGER');
|
40
|
+
this.close_btn = document.getElementById('equation-close-btn');
|
41
|
+
this.close_btn.addEventListener(
|
42
|
+
'click', (event) => UI.toggleDialog(event));
|
43
|
+
this.table = document.getElementById('equation-table');
|
44
|
+
this.scroll_area = document.getElementById('equation-scroll-area');
|
45
|
+
|
46
|
+
// Make toolbar buttons responsive
|
47
|
+
document.getElementById('eq-new-btn').addEventListener(
|
48
|
+
'click', () => EQUATION_MANAGER.promptForEquation());
|
49
|
+
document.getElementById('eq-rename-btn').addEventListener(
|
50
|
+
'click', () => EQUATION_MANAGER.promptForName());
|
51
|
+
document.getElementById('eq-edit-btn').addEventListener(
|
52
|
+
'click', () => EQUATION_MANAGER.editEquation());
|
53
|
+
document.getElementById('eq-delete-btn').addEventListener(
|
54
|
+
'click', () => EQUATION_MANAGER.deleteEquation());
|
55
|
+
|
56
|
+
// Create modal dialogs
|
57
|
+
this.new_modal = new ModalDialog('new-equation');
|
58
|
+
this.new_modal.ok.addEventListener(
|
59
|
+
'click', () => EQUATION_MANAGER.newEquation());
|
60
|
+
this.new_modal.cancel.addEventListener(
|
61
|
+
'click', () => EQUATION_MANAGER.cancelEquation());
|
62
|
+
|
63
|
+
this.rename_modal = new ModalDialog('rename-equation');
|
64
|
+
this.rename_modal.ok.addEventListener(
|
65
|
+
'click', () => EQUATION_MANAGER.renameEquation());
|
66
|
+
this.rename_modal.cancel.addEventListener(
|
67
|
+
'click', () => EQUATION_MANAGER.rename_modal.hide());
|
68
|
+
|
69
|
+
// Initialize the dialog properties
|
70
|
+
this.reset();
|
71
|
+
}
|
72
|
+
|
73
|
+
reset() {
|
74
|
+
this.visible = false;
|
75
|
+
this.selected_modifier = null;
|
76
|
+
this.edited_expression = null;
|
77
|
+
this.last_time_clicked = 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
doubleClicked(obj) {
|
81
|
+
const
|
82
|
+
now = Date.now(),
|
83
|
+
dt = now - this.last_time_clicked;
|
84
|
+
this.last_time_clicked = now;
|
85
|
+
if(obj === this.clicked_object) {
|
86
|
+
// Consider click to be "double" if it occurred less than 300 ms ago
|
87
|
+
if(dt < 300) {
|
88
|
+
this.last_time_clicked = 0;
|
89
|
+
return true;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
this.clicked_object = obj;
|
93
|
+
return false;
|
94
|
+
}
|
95
|
+
|
96
|
+
enterKey() {
|
97
|
+
// Open the expression editor for the selected equation
|
98
|
+
const srl = this.table.getElementsByClassName('sel-set');
|
99
|
+
if(srl.length > 0) {
|
100
|
+
const r = this.table.rows[srl[0].rowIndex];
|
101
|
+
if(r) {
|
102
|
+
// Emulate a double-click on the second cell to edit the expression
|
103
|
+
this.last_time_clicked = Date.now();
|
104
|
+
r.cells[1].dispatchEvent(new Event('click'));
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
upDownKey(dir) {
|
110
|
+
// Select row above or below the selected one (if possible)
|
111
|
+
const srl = this.table.getElementsByClassName('sel-set');
|
112
|
+
if(srl.length > 0) {
|
113
|
+
const r = this.table.rows[srl[0].rowIndex + dir];
|
114
|
+
if(r) {
|
115
|
+
UI.scrollIntoView(r);
|
116
|
+
// NOTE: not row but cell listens for onclick
|
117
|
+
r.cells[1].dispatchEvent(new Event('click'));
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
updateDialog() {
|
123
|
+
// Updates equation list, highlighting selected equation (if any)
|
124
|
+
const
|
125
|
+
ed = MODEL.equations_dataset,
|
126
|
+
ml = [],
|
127
|
+
msl = ed.selectorList,
|
128
|
+
sm = this.selected_modifier;
|
129
|
+
let smid = 'eqmtr';
|
130
|
+
for(let i = 0; i < msl.length; i++) {
|
131
|
+
const
|
132
|
+
m = ed.modifiers[UI.nameToID(msl[i])],
|
133
|
+
wild = (m.selector.indexOf('??') >= 0),
|
134
|
+
clk = '" onclick="EQUATION_MANAGER.selectModifier(event, \'' +
|
135
|
+
m.selector + '\'';
|
136
|
+
if(m === sm) smid += i;
|
137
|
+
ml.push(['<tr id="eqmtr', i, '" class="dataset-modif',
|
138
|
+
(m === sm ? ' sel-set' : ''),
|
139
|
+
'"><td class="equation-selector',
|
140
|
+
(m.expression.isStatic ? '' : ' it'),
|
141
|
+
(wild ? ' wildcard' : ''), clk, ', false);">',
|
142
|
+
(wild ? wildcardFormat(m.selector) : m.selector),
|
143
|
+
'</td><td class="equation-expression',
|
144
|
+
clk, ');">', m.expression.text, '</td></tr>'].join(''));
|
145
|
+
}
|
146
|
+
this.table.innerHTML = ml.join('');
|
147
|
+
this.scroll_area.style.display = 'block';
|
148
|
+
if(sm) UI.scrollIntoView(document.getElementById(smid));
|
149
|
+
const btns = 'eq-rename eq-edit eq-delete';
|
150
|
+
if(sm) {
|
151
|
+
UI.enableButtons(btns);
|
152
|
+
} else {
|
153
|
+
UI.disableButtons(btns);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
showInfo(id, shift) {
|
158
|
+
// @@TO DO: Display documentation for the equation => extra comments field?
|
159
|
+
}
|
160
|
+
|
161
|
+
selectModifier(event, id, x=true) {
|
162
|
+
// Select modifier, or when Alt- or double-clicked, edit its expression
|
163
|
+
// or the equation name (= name of the modifier)
|
164
|
+
if(MODEL.equations_dataset) {
|
165
|
+
const
|
166
|
+
m = MODEL.equations_dataset.modifiers[UI.nameToID(id)] || null,
|
167
|
+
edit = event.altKey || this.doubleClicked(m);
|
168
|
+
this.selected_modifier = m;
|
169
|
+
if(m && edit) {
|
170
|
+
if(x) {
|
171
|
+
this.editEquation();
|
172
|
+
} else {
|
173
|
+
this.promptForName();
|
174
|
+
}
|
175
|
+
return;
|
176
|
+
}
|
177
|
+
} else {
|
178
|
+
this.selected_modifier = null;
|
179
|
+
}
|
180
|
+
this.updateDialog();
|
181
|
+
}
|
182
|
+
|
183
|
+
promptForEquation(add=false) {
|
184
|
+
this.add_to_chart = add;
|
185
|
+
this.new_modal.element('name').value = '';
|
186
|
+
this.new_modal.show('name');
|
187
|
+
}
|
188
|
+
|
189
|
+
newEquation() {
|
190
|
+
const
|
191
|
+
n = this.new_modal.element('name').value.trim(),
|
192
|
+
m = MODEL.equations_dataset.addModifier(n);
|
193
|
+
if(m) {
|
194
|
+
this.new_modal.hide();
|
195
|
+
this.selected_modifier = m;
|
196
|
+
this.updateDialog();
|
197
|
+
// Open expression editor if expression is still undefined
|
198
|
+
if(!m.expression.text) this.editEquation();
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
editEquation() {
|
203
|
+
const m = this.selected_modifier;
|
204
|
+
if(m) {
|
205
|
+
this.edited_expression = m.expression;
|
206
|
+
const md = UI.modals.expression;
|
207
|
+
md.element('property').innerHTML = this.selected_modifier.selector;
|
208
|
+
md.element('text').value = m.expression.text;
|
209
|
+
document.getElementById('variable-obj').value = 0;
|
210
|
+
X_EDIT.updateVariableBar();
|
211
|
+
X_EDIT.clearStatusBar();
|
212
|
+
md.show('text');
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
cancelEquation() {
|
217
|
+
this.new_modal.hide();
|
218
|
+
this.add_to_chart = false;
|
219
|
+
}
|
220
|
+
|
221
|
+
modifyEquation(x) {
|
222
|
+
// Update and compile expression only if it has been changed
|
223
|
+
if(this.edited_expression && x != this.edited_expression.text) {
|
224
|
+
this.edited_expression.text = x;
|
225
|
+
this.edited_expression.compile();
|
226
|
+
}
|
227
|
+
this.edited_expression.reset();
|
228
|
+
this.edited_expression = null;
|
229
|
+
this.updateDialog();
|
230
|
+
CHART_MANAGER.updateDialog();
|
231
|
+
if(this.add_to_chart && CHART_MANAGER.chart_index >= 0) {
|
232
|
+
// Add selected modifier as new equation to chart
|
233
|
+
CHART_MANAGER.addVariable(this.selected_modifier.selector);
|
234
|
+
this.add_to_chart = false;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
promptForName() {
|
239
|
+
// Prompts the modeler for a new name for the selected equation (if any)
|
240
|
+
if(this.selected_modifier) {
|
241
|
+
this.rename_modal.element('name').value = this.selected_modifier.selector;
|
242
|
+
this.rename_modal.show('name');
|
243
|
+
}
|
244
|
+
}
|
245
|
+
|
246
|
+
renameEquation() {
|
247
|
+
if(!this.selected_modifier) return;
|
248
|
+
const
|
249
|
+
sel = this.rename_modal.element('name').value,
|
250
|
+
// Keep track of old name
|
251
|
+
oldm = this.selected_modifier,
|
252
|
+
olds = oldm.selector,
|
253
|
+
// NOTE: addModifier returns existing one if selector not changed
|
254
|
+
m = MODEL.equations_dataset.addModifier(sel);
|
255
|
+
// NULL indicates invalid name
|
256
|
+
if(!m) return;
|
257
|
+
// If only case has changed, update the selector
|
258
|
+
// NOTE: equation names may contain spaces; if so, reduce to single space
|
259
|
+
if(m === oldm) {
|
260
|
+
m.selector = sel.trim().replace(/\s+/g, ' ');
|
261
|
+
} else {
|
262
|
+
// When a new modifier has been added, more actions are needed
|
263
|
+
m.expression = oldm.expression;
|
264
|
+
this.deleteEquation();
|
265
|
+
this.selected_modifier = m;
|
266
|
+
}
|
267
|
+
// Update all chartvariables referencing this dataset + old selector
|
268
|
+
let cv_cnt = 0;
|
269
|
+
for(let i = 0; i < MODEL.charts.length; i++) {
|
270
|
+
const c = MODEL.charts[i];
|
271
|
+
for(let j = 0; j < c.variables.length; j++) {
|
272
|
+
const v = c.variables[j];
|
273
|
+
if(v.object === MODEL.equations_dataset && v.attribute === olds) {
|
274
|
+
v.attribute = m.selector;
|
275
|
+
cv_cnt++;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
}
|
279
|
+
// Also replace old selector in all expressions (count these as well)
|
280
|
+
// NOTE: equation selectors in variables are similar to entity names
|
281
|
+
const xr_cnt = MODEL.replaceEntityInExpressions(olds, m.selector);
|
282
|
+
// Notify modeler of changes (if any)
|
283
|
+
const msg = [];
|
284
|
+
if(cv_cnt) msg.push(pluralS(cv_cnt, ' chart variable'));
|
285
|
+
if(xr_cnt) msg.push(pluralS(xr_cnt, ' expression variable'));
|
286
|
+
if(msg.length) {
|
287
|
+
UI.notify('Updated ' + msg.join(' and '));
|
288
|
+
// Also update these stay-on-top dialogs, as they may display a
|
289
|
+
// variable name for this dataset + modifier
|
290
|
+
UI.updateControllerDialogs('CDEFJX');
|
291
|
+
}
|
292
|
+
// Always close the name prompt dialog, and update the equation manager
|
293
|
+
this.rename_modal.hide();
|
294
|
+
this.updateDialog();
|
295
|
+
}
|
296
|
+
|
297
|
+
deleteEquation() {
|
298
|
+
const m = this.selected_modifier;
|
299
|
+
if(m) {
|
300
|
+
delete MODEL.equations_dataset.modifiers[UI.nameToID(m.selector)];
|
301
|
+
this.selected_modifier = null;
|
302
|
+
this.updateDialog();
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
} // END of class EquationManager
|
307
|
+
|