Skip to content

Commit aafbbee

Browse files
New workflow, new contraint, and new dense on/off.
1 parent 08e8896 commit aafbbee

14 files changed

Lines changed: 300 additions & 202 deletions

Knapsack.aimms

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<References AIMMS_Version="4.87.6.3 (x64)">
2+
<References AIMMS_Version="4.93.1.1 (x64)">
33
<MainProject Path="MainProject" />
44
<Library System="true" Path="AimmsPro" />
55
<Library System="true" Path="AimmsWebUI" />

MainProject/Knapsack.ams

Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ Model Main_Knapsack {
4040
Set s_items {
4141
Index: i_item;
4242
Parameter: ep_selectedItem;
43-
Comment: "ElementRange(1, p_maxItems, prefix:\"item-\", fill:1)";
43+
Definition: ElementRange(1, p_itemQuantity, prefix:"item-", fill:1);
4444
}
4545
StringParameter sp_itemDescription {
4646
IndexDomain: i_item;
47+
InitialData: "";
4748
}
48-
Parameter p_maxItems {
49+
Parameter p_itemQuantity {
4950
Text: "No. of items";
5051
Range: integer;
5152
InitialData: 14;
@@ -59,33 +60,47 @@ Model Main_Knapsack {
5960
Parameter p_itemWeight {
6061
IndexDomain: (i_item);
6162
Unit: lb;
63+
InitialData: 0;
6264
}
6365
Parameter p_maxWeightKnapsack {
6466
Text: "Max. weight knapsack";
6567
Unit: lb;
6668
InitialData: 60;
6769
}
70+
Parameter p_maxItemKnapsack {
71+
Text: "Max. item knapsack";
72+
InitialData: 10;
73+
}
6874
Parameter p_itemRangeMin {
6975
IndexDomain: (i_item);
7076
Range: integer;
77+
InitialData: 0;
7178
}
7279
Parameter p_itemRangeMax {
7380
IndexDomain: (i_item);
7481
Range: integer;
82+
InitialData: 0;
83+
webui::AnnotationsIdentifier: sp_maxRangeAnnotation;
84+
webui::TooltipIdentifier: sp_maxRangeTooltip;
7585
}
7686
Parameter p_itemBound {
7787
IndexDomain: (i_item);
7888
Text: "No. of copies that is allowed";
7989
Range: integer;
90+
InitialData: 0;
8091
}
8192
}
8293
Procedure pr_randomizeData {
8394
Body: {
84-
empty p_itemValue, p_itemWeight, p_itemBound;
95+
empty p_itemValue, p_itemWeight, p_itemBound, p_itemRangeMax;
96+
97+
p_itemValue(i_item) := uniform(0, 200)*1[$];
98+
p_itemWeight(i_item) := uniform(0[lb], p_maxWeightKnapsack/3);
99+
p_itemBound(i_item) := ceil(uniform(0, 10));
85100

86-
p_itemValue(i_item) := uniform(0,200)*1[$];
87-
p_itemWeight(i_item) := uniform(0[lb],p_maxWeightKnapsack/3);
88-
p_itemBound(i_item) := ceil(uniform(0,10));
101+
!not random
102+
p_itemRangeMax(i_item) := 1;
103+
sp_itemDescription(i_item) := i_item;
89104
}
90105
}
91106
}
@@ -122,6 +137,9 @@ Model Main_Knapsack {
122137
Unit: lb;
123138
Definition: sum(i_item, v_inline_knapsackWeight(i_item)) <= p_maxWeightKnapsack;
124139
}
140+
Constraint c_limitKnapsackItem {
141+
Definition: sum(i_item, v_knapsackItems(i_item)) <= p_maxItemKnapsack;
142+
}
125143
MathematicalProgram mp_knapsackModel {
126144
Objective: v_knapsackTotalValue;
127145
Direction: maximize;
@@ -213,7 +231,7 @@ Model Main_Knapsack {
213231
{ ( '1', '1', 'displayText' ) : "Welcome" , ( '1', '1', 'icon' ) : "aimms-happy" ,
214232
( '1', '1', 'pageId' ) : "home" , ( '1', '1', 'tooltip' ) : "welcome" ,
215233
( '1', '1', 'workflowPageState' ) : "active" , ( '1', '1', 'pageDataState' ) : "Incomplete" ,
216-
( '1', '1', 'redirectPageId' ) : "home" , ( '1', '2', 'displayText' ) : "Story" ,
234+
( '1', '1', 'redirectPageId' ) : "" , ( '1', '2', 'displayText' ) : "Story" ,
217235
( '1', '2', 'icon' ) : "aimms-lamp5" , ( '1', '2', 'pageId' ) : "problem_description",
218236
( '1', '2', 'tooltip' ) : "Problem description", ( '1', '2', 'workflowPageState' ) : "active" ,
219237
( '1', '2', 'pageDataState' ) : "Incomplete" , ( '1', '2', 'redirectPageId' ) : "home" ,
@@ -227,71 +245,68 @@ Model Main_Knapsack {
227245
}
228246
}
229247
}
230-
Section CRUD {
231-
StringParameter sp_addEditElement;
232-
Section CRUD_Items {
233-
Procedure pr_openAddItem {
234-
Body: {
235-
empty sp_addEditElement;
236-
237-
webui::OpenDialogPage(
238-
pageId : 'crud',
239-
title : "Add Items",
240-
actions : s_loc_actions,
241-
onDone : 'pr_addItem');
242-
}
243-
Set s_loc_actions {
244-
InitialData: {
245-
{'Cancel', 'OK'}
246-
}
247-
}
248-
}
249-
Procedure pr_addItem {
250-
Arguments: sp_arg_action;
251-
Body: {
252-
if sp_arg_action = 'OK' then
253-
ep_selectedItem := StringToElement(s_items, sp_addEditElement, 1);
254-
endif;
255-
}
256-
StringParameter sp_arg_action {
257-
Property: Input;
258-
}
259-
}
260-
Procedure pr_openEditItem {
261-
Body: {
262-
sp_addEditElement := ep_selectedItem;
263-
264-
webui::OpenDialogPage(
265-
pageId : 'crud',
266-
title : "Edit Restaurant",
267-
actions : s_loc_actions,
268-
onDone : 'pr_editItem');
269-
}
270-
Set s_loc_actions {
271-
InitialData: {
272-
{'Cancel', 'OK'}
273-
}
274-
}
248+
Section Status_Bar {
249+
Procedure pr_changeVisibility {
250+
Body: {
251+
if bp_dense then
252+
253+
sp_statusBar('1', 'header') := "Visibility";
254+
sp_statusBar('1', 'icon') := "aimms-filter";
255+
sp_statusBar('1', 'color') := "#505767";
256+
sp_statusBar('1', 'text') := "Showing Sparse";
257+
sp_statusBar('1', 'tooltip') := "Click to change visibility";
258+
sp_statusBar('1', 'procedure') := "pr_changeVisibility";
259+
sp_statusBar('1', 'state') := "active";
260+
261+
bp_sparse := 1;
262+
bp_dense := 0;
263+
264+
elseif bp_sparse then
265+
266+
sp_statusBar('1', 'header') := "Visibility";
267+
sp_statusBar('1', 'icon') := "aimms-filter2";
268+
sp_statusBar('1', 'color') := "#505767";
269+
sp_statusBar('1', 'text') := "Showing Dense";
270+
sp_statusBar('1', 'tooltip') := "Click to change visibility";
271+
sp_statusBar('1', 'procedure') := "pr_changeVisibility";
272+
sp_statusBar('1', 'state') := "active";
273+
274+
bp_sparse := 0;
275+
bp_dense := 1;
276+
endif;
275277
}
276-
Procedure pr_editItem {
277-
Arguments: sp_arg_action;
278-
Body: {
279-
if sp_arg_action = 'OK' then
280-
SetElementRename(s_items, ep_selectedItem, sp_addEditElement);
281-
endif;
282-
}
283-
StringParameter sp_arg_action {
284-
Property: Input;
285-
}
278+
Comment: "Showing Dense/ Showing Sparse/ Showing Inactives";
279+
}
280+
Procedure pr_setInitialStatusBar {
281+
Body: {
282+
empty sp_statusBar;
283+
284+
sp_statusBar('1', 'header') := "Visibility";
285+
sp_statusBar('1', 'icon') := "aimms-filter";
286+
sp_statusBar('1', 'color') := "#505767";
287+
sp_statusBar('1', 'text') := "Showing Sparse";
288+
sp_statusBar('1', 'tooltip') := "Click to change visibility";
289+
sp_statusBar('1', 'procedure') := "pr_changeVisibility";
290+
sp_statusBar('1', 'state') := "active";
291+
bp_sparse := 1;
286292
}
287-
Procedure pr_deleteItem {
288-
Body: {
289-
s_items -= ep_selectedItem;
290-
291-
ep_selectedItem := first(i_item);
292-
}
293+
}
294+
StringParameter sp_statusBar {
295+
IndexDomain: (webui::indexApplicationExtension,webui::indexStatusBarSpec);
296+
InitialData: {
297+
data
298+
{ ( 1, header ) : "Visibility" , ( 1, icon ) : "aimms-filter" ,
299+
( 1, color ) : "red" , ( 1, text ) : "Showing Inactive" ,
300+
( 1, tooltip ) : "Click to change visibility", ( 1, procedure ) : "pr_changeVisibility" ,
301+
( 1, state ) : "active" }
293302
}
294303
}
304+
Parameter bp_sparse {
305+
InitialData: 0;
306+
}
307+
Parameter bp_dense {
308+
InitialData: 0;
309+
}
295310
}
296311
Section Pages {
297312
Section Inputs_Page {
@@ -313,51 +328,22 @@ Model Main_Knapsack {
313328
( 6, procedure ) : "pr_solveKnapsackModelBounded" , ( 6, state ) : "active" }
314329
}
315330
}
316-
StringParameter sp_itemItemActions {
317-
IndexDomain: (webui::indexWidgetItemActionSpec,webui::indexPageExtension,webui::indexWidgetActionSpec);
318-
Definition: {
319-
data
320-
{ ( p_itemBound , 1, displaytext ) : "Add" , ( p_itemBound , 1, icon ) : "aimms-plus3" ,
321-
( p_itemBound , 1, procedure ) : "pr_openAddItem" , ( p_itemBound , 1, state ) : "active" ,
322-
( p_itemBound , 2, displaytext ) : "Edit" , ( p_itemBound , 2, icon ) : "aimms-pencil2" ,
323-
( p_itemBound , 2, procedure ) : "pr_openEditItem", ( p_itemBound , 2, state ) : "active" ,
324-
( p_itemBound , 3, displaytext ) : "Delete" , ( p_itemBound , 3, icon ) : "aimms-eraser2" ,
325-
( p_itemBound , 3, procedure ) : "pr_deleteItem" , ( p_itemBound , 3, state ) : "active" ,
326-
( p_itemRangeMax , 1, displaytext ) : "Add" , ( p_itemRangeMax , 1, icon ) : "aimms-plus3" ,
327-
( p_itemRangeMax , 1, procedure ) : "pr_openAddItem" , ( p_itemRangeMax , 1, state ) : "active" ,
328-
( p_itemRangeMax , 2, displaytext ) : "Edit" , ( p_itemRangeMax , 2, icon ) : "aimms-pencil2" ,
329-
( p_itemRangeMax , 2, procedure ) : "pr_openEditItem", ( p_itemRangeMax , 2, state ) : "active" ,
330-
( p_itemRangeMax , 3, displaytext ) : "Delete" , ( p_itemRangeMax , 3, icon ) : "aimms-eraser2" ,
331-
( p_itemRangeMax , 3, procedure ) : "pr_deleteItem" , ( p_itemRangeMax , 3, state ) : "active" ,
332-
( p_itemRangeMin , 1, displaytext ) : "Add" , ( p_itemRangeMin , 1, icon ) : "aimms-plus3" ,
333-
( p_itemRangeMin , 1, procedure ) : "pr_openAddItem" , ( p_itemRangeMin , 1, state ) : "active" ,
334-
( p_itemRangeMin , 2, displaytext ) : "Edit" , ( p_itemRangeMin , 2, icon ) : "aimms-pencil2" ,
335-
( p_itemRangeMin , 2, procedure ) : "pr_openEditItem", ( p_itemRangeMin , 2, state ) : "active" ,
336-
( p_itemRangeMin , 3, displaytext ) : "Delete" , ( p_itemRangeMin , 3, icon ) : "aimms-eraser2" ,
337-
( p_itemRangeMin , 3, procedure ) : "pr_deleteItem" , ( p_itemRangeMin , 3, state ) : "active" ,
338-
( p_itemValue , 1, displaytext ) : "Add" , ( p_itemValue , 1, icon ) : "aimms-plus3" ,
339-
( p_itemValue , 1, procedure ) : "pr_openAddItem" , ( p_itemValue , 1, state ) : "active" ,
340-
( p_itemValue , 2, displaytext ) : "Edit" , ( p_itemValue , 2, icon ) : "aimms-pencil2" ,
341-
( p_itemValue , 2, procedure ) : "pr_openEditItem", ( p_itemValue , 2, state ) : "active" ,
342-
( p_itemValue , 3, displaytext ) : "Delete" , ( p_itemValue , 3, icon ) : "aimms-eraser2" ,
343-
( p_itemValue , 3, procedure ) : "pr_deleteItem" , ( p_itemValue , 3, state ) : "active" ,
344-
( p_itemWeight , 1, displaytext ) : "Add" , ( p_itemWeight , 1, icon ) : "aimms-plus3" ,
345-
( p_itemWeight , 1, procedure ) : "pr_openAddItem" , ( p_itemWeight , 1, state ) : "active" ,
346-
( p_itemWeight , 2, displaytext ) : "Edit" , ( p_itemWeight , 2, icon ) : "aimms-pencil2" ,
347-
( p_itemWeight , 2, procedure ) : "pr_openEditItem", ( p_itemWeight , 2, state ) : "active" ,
348-
( p_itemWeight , 3, displaytext ) : "Delete" , ( p_itemWeight , 3, icon ) : "aimms-eraser2" ,
349-
( p_itemWeight , 3, procedure ) : "pr_deleteItem" , ( p_itemWeight , 3, state ) : "active" ,
350-
( sp_itemDescription, 1, displaytext ) : "Add" , ( sp_itemDescription, 1, icon ) : "aimms-plus3" ,
351-
( sp_itemDescription, 1, procedure ) : "pr_openAddItem" , ( sp_itemDescription, 1, state ) : "active" ,
352-
( sp_itemDescription, 2, displaytext ) : "Edit" , ( sp_itemDescription, 2, icon ) : "aimms-pencil2" ,
353-
( sp_itemDescription, 2, procedure ) : "pr_openEditItem", ( sp_itemDescription, 2, state ) : "active" ,
354-
( sp_itemDescription, 3, displaytext ) : "Delete" , ( sp_itemDescription, 3, icon ) : "aimms-eraser2" ,
355-
( sp_itemDescription, 3, procedure ) : "pr_deleteItem" , ( sp_itemDescription, 3, state ) : "active" }
356-
}
331+
StringParameter sp_maxRangeTooltip {
332+
Definition: "This idenfifier may change after the run.";
333+
}
334+
StringParameter sp_maxRangeAnnotation {
335+
Definition: "different";
357336
}
358337
}
359338
Section Results_Page {
360339
DeclarationSection Result_Side_Panel {
340+
Set s_def_filteredItems {
341+
SubsetOf: s_items;
342+
Index: i_fitem;
343+
Definition: {
344+
{i_item | p_itemFilter(i_item)}
345+
}
346+
}
361347
StringParameter sp_resultsSidePanel {
362348
IndexDomain: (webui::indexPageExtension,webui::indexSidePanelSpec);
363349
Definition: {
@@ -391,6 +377,17 @@ Model Main_Knapsack {
391377
round(v_inline_knapsackValue(i_item), 2))
392378
}
393379
}
380+
Parameter p_dom_knapsackResult {
381+
IndexDomain: i_item;
382+
Definition: {
383+
1 $ (!used by status bar visualization
384+
(v_knapsackItems(i_item)
385+
and v_inline_knapsackValue(i_item)
386+
and bp_dense)
387+
or
388+
bp_sparse)
389+
}
390+
}
394391
}
395392
}
396393
}
@@ -468,7 +465,7 @@ Model Main_Knapsack {
468465
block ! ReadSingleValue Import
469466
axll::SelectSheet("Knapsack");
470467

471-
axll::ReadSingleValue(p_maxItems, "B1");
468+
axll::ReadSingleValue(p_maxItemKnapsack, "B1");
472469
axll::ReadSingleValue(p_maxWeightKnapsack, "B2");
473470

474471
endblock;
@@ -523,7 +520,7 @@ Model Main_Knapsack {
523520
axll::CreateSheet("Knapsack", "Item");
524521

525522
axll::WriteSingleValue(sp_loc_maxItemsTitle, "A1");
526-
axll::WriteSingleValue(p_maxItems, "B1");
523+
axll::WriteSingleValue(p_maxItemKnapsack, "B1");
527524

528525
axll::WriteSingleValue(sp_loc_maxWeightKnapsackTitle, "A2");
529526
axll::WriteSingleValue(p_maxWeightKnapsack, "B2");
@@ -588,6 +585,9 @@ Model Main_Knapsack {
588585
}
589586
}
590587
Procedure MainInitialization {
588+
Body: {
589+
pr_setInitialStatusBar;
590+
}
591591
Comment: "Add initialization statements here that do NOT require any library being initialized already.";
592592
}
593593
Procedure PostMainInitialization {

MainProject/Knapsack.nch

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
"Main_CarSelection" "Main_Knapsack" "2022-06-06 19:33:44"
99
"pr_dataGenerator" "pr_randomizeData" "2022-08-09 20:26:41"
1010
"ep_item" "ep_selectedItem" "2022-08-09 20:33:49"
11-
"pr_openAddRestaurant" "pr_openAddItem" "2022-08-09 20:36:10"
12-
"pr_addRestaurant" "pr_addItem" "2022-08-09 20:36:15"
13-
"pr_openEditRestaurant" "pr_openEditItem" "2022-08-09 20:36:18"
14-
"pr_editRestaurant" "pr_editItem" "2022-08-09 20:36:22"
15-
"pr_deleteRestaurant" "pr_deleteItem" "2022-08-09 20:36:25"
1611
"Procedure_1" "pr_dev_axllExamples" "2022-08-15 15:58:04"
1712
"pr_dev_axllExamples" "pr_dev_axllWriteExamples" "2022-08-15 15:58:14"
1813
"sp_masterSecondaryActions" "sp_inputSecondaryActions" "2022-08-15 18:52:55"
1914
"sp_inputSecondaryActions" "sp_inputsSecondaryActions" "2022-08-15 18:53:05"
20-
"sp" "sp_itemItemActions" "2022-08-15 19:15:36"
2115
"v_knapsackValue" "v_inline_knapsackValue" "2022-08-16 19:49:42"
2216
"v_knapsackValue_definition" "v_inline_knapsackValue_definition" "2022-08-16 19:49:42"
2317
"sp_" "sp_tooltipPerWeight" "2022-09-01 20:12:20"
2418
"Copy_sp_tooltipPerWeight" "sp_tooltipPerQuantity" "2022-09-01 20:13:08"
19+
"p_maxItems" "p_itemQuantity" "2023-04-14 18:19:10"
20+
"Copy_p_maxWeightKnapsack" "p_maxItemKnapsack" "2023-04-14 18:19:44"
21+
"Copy_c_limitKnapsackWeight" "c_limitKnapsackItem" "2023-04-14 18:23:37"
22+
"sp_p" "sp_maxRangeTooltip" "2023-04-14 18:30:20"
23+
"Copy_sp_maxRangeTooltip" "_sp_maxRangeAnnotation" "2023-04-14 18:34:30"
24+
"_sp_maxRangeAnnotation" "sp_maxRangeAnnotation" "2023-04-14 18:34:32"
25+
"Section_1" "Status_Bar" "2023-04-14 18:38:15"

MainProject/Project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<Project AimmsVersion="4.87.6.3 unicode x64" ProjectUUID="F8A29558-2CFD-43C6-BD03-CB304C7E812C">
2+
<Project AimmsVersion="4.93.1.1 unicode x64" ProjectUUID="F8A29558-2CFD-43C6-BD03-CB304C7E812C">
33
<ModelFileName>Knapsack.ams</ModelFileName>
44
<AutoSaveAndBackup>
55
<DataBackup AtRegularInterval="true" EveryNMinutes="15" NumBackupsDatedToday="3" NumDaysBeforeToday="3" />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.annotation-different {
2+
background: #ff921e2a;
3+
}

0 commit comments

Comments
 (0)