-
Notifications
You must be signed in to change notification settings - Fork 1
/
strips.js
983 lines (843 loc) · 29.6 KB
/
strips.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
function incCount(func)
{
if(func.count == undefined)
{
func.count = 0;
}
func.count++;
}
class OrderedList
{
constructor(sortFunction)
{
//Internal array
this.array = [];
//Function that gets the value to sort by
this.sortFunc = sortFunction;
}
getBestElement()
{
//The list is sorted from worst to best so the best element can be removed off of the top
let ele = this.array.pop();
return ele;
}
addElement(element)
{
//Elements are added by performing a binary search and then inserting the element at the correct location
//If the list is empty, directly add the element to the array
if(this.array.length==0)
{
this.array.push(element);
return;
}
//Minimum possible index is 0 and the maximum index is length-1
let min = 0;
let max = this.array.length-1;
//The value of the element
let cost = this.sortFunc(element);
//Loop until the element is found
while(true)
{
//Makes a guess about the index directly between the 2 extremes
let guess = Math.ceil((min+max)/2);
//If the minimum is equal or greater than the the maximum the location to splice the element in is found
if(max<=min)
{
let newCost = this.sortFunc(this.array[max]);
if(cost<newCost)
{
this.array.splice(guess+1,0,element);
return;
}
else if(cost>newCost)
{
this.array.splice(guess,0,element);
return;
}
}
//Gets the value of the guess
let newCost = this.sortFunc(this.array[guess]);
//If it is underestimating then the maximum index is updated eliminating all entries in the list smaller than the current guess
if(cost>newCost)
{
max = guess-1;
}
//If it is overestimating then the minimum index is updated eliminating all entries in the list larger than the current guess
else if(cost<newCost)
{
min = guess+1;
}
//If the value of the guess is correct the element is added at the location of the guess
else if(cost==newCost)
{
this.array.splice(guess,0,element);
return;
}
}
}
}
//Unused
//Might be memory leaky but if that is patched this could be a viable alternative to semi sorted
class SortedQueue
{
constructor(maxExpected)
{
this.openStatesSearch = {};
this.openStatesList = [];
this.spliceCount = 0;
this.maxExpected = maxExpected;
this.worstCost = Infinity;
}
getBestElement()
{
let ele = this.openStatesList.pop();
delete this.openStatesSearch[ele.str];
return ele;
}
addElement(element)
{
if(element.fCost > this.worstCost)
{
return;
}
this.openStatesSearch[element.str] = element;
if (this.openStatesList.length == 0)
{
this.openStatesList.push(element);
return;
}
let min = 0;
let max = this.openStatesList.length - 1;
let cost = element.fCost;
while (true)
{
let newExtreme = Math.ceil((min + max) / 2);
if (max - min <= 0)
{
let newCost = this.openStatesList[max].fCost;
if (cost < newCost)
{
this.openStatesList.splice(newExtreme + 1, 0, element);
this.worstCost = this.openStatesList[0];
while(this.openStatesList.length>this.maxExpected)
{
delete this.openStatesSearch[this.openStatesList.shift().str];
}
return;
}
else if (cost > newCost)
{
this.openStatesList.splice(newExtreme, 0, element);
this.worstCost = this.openStatesList[0];
while(this.openStatesList.length>this.maxExpected)
{
delete this.openStatesSearch[this.openStatesList.shift().str];
}
return;
}
}
let newCost = this.openStatesList[newExtreme].fCost;
if (cost > newCost)
{
max = newExtreme - 1;
}
else if (cost < newCost)
{
min = newExtreme + 1;
}
else if (cost == newCost)
{
this.openStatesList.splice(newExtreme, 0, element);
this.worstCost = this.openStatesList[0];
this.spliceCount++;
while(this.openStatesList.length>this.maxExpected)
{
delete this.openStatesSearch[this.openStatesList.shift().str];
}
return;
}
}
}
getElementByStr(str)
{
return this.openStatesSearch[str];
}
}
//Unused
//Example of what happens if you try to manually search the list for the best element
//Large state spaces are VERY slow with this
class UnsortedQueue
{
constructor()
{
this.openStatesSearch = {};
}
getBestElement()
{
let bestCost = Infinity;
let bestIndex = 0;
for(let i in this.openStatesSearch)
{
let cost = this.openStatesSearch[i].fCost;
if(cost<bestCost)
{
bestCost = cost;
bestIndex = i;
}
}
let ele = this.openStatesSearch[bestIndex];
delete this.openStatesSearch[bestIndex];
return ele;
}
addElement(element)
{
this.openStatesSearch[element.str] = element;
}
getElementByStr(str)
{
return this.openStatesSearch[str];
}
}
/*
This is what is used to retrieve the best element
It works by splitting up the data into 2 lists: a good list, and a bad list
The good list length is 2xsqrt of the the total length
New entries are sorted into the good or bad list based on whether they are better than the worst element in the good list
If the good list is empty or twice the length that it is supposed to be, the lists are resorted and the boundry value is reset
During a resort, if the total length is greater than the max expected length, the extra items are removed
This can be sped up by using js sort to remove excess elements rather than the OrderedList which uses splice
*/
class SemiSortedQueue
{
constructor(maxExpectedLength)
{
this.openStatesSearch = {};
this.badList = [];
this.badVacancies = [];
this.badLength = 0;
this.goodList = [];
this.goodVacancies = [];
this.goodLength = 0;
this.goodMaxLength = 50;
this.goodThreshold = 20;
this.sortedMode = false;
this.maxExpectedLength = maxExpectedLength;
this.boundryCost = Infinity;
this.worstCost = Infinity;
}
getBestElement()
{
if(this.goodLength+this.badLength<this.goodThreshold)
{
this.switchSortedMode(false);
}
else
{
this.switchSortedMode(true);
}
if(this.goodLength <= 0)
{
this.resort();
}
if(this.goodLength <= 0)
{
console.error("Error: Cannot retrieve an element from an empty list")
}
let bestCost = Infinity;
let bestCostIndex;
for(let i = 0; i < this.goodList.length; i++)
{
let testEle = this.goodList[i];
if(testEle != undefined)
{
if(testEle.fCost<bestCost)
{
bestCost = testEle.fCost;
bestCostIndex = i;
}
}
}
let bestEle = this.goodList[bestCostIndex];
delete this.goodList[bestCostIndex];
this.goodLength--;
this.goodVacancies.push(bestCostIndex);
if(this.openStatesSearch[bestEle.str] == undefined)
{
delete this.openStatesSearch[bestEle.str];
return this.getBestElement();
}
else if(this.openStatesSearch[bestEle.str].cost<bestEle.cost)
{
delete this.openStatesSearch[bestEle.str];
console.log("Duplicate Element Detected")
return this.getBestElement();
}
delete this.openStatesSearch[bestEle.str];
return bestEle;
}
addElement(element)
{
if(this.goodLength+this.badLength<this.goodThreshold)
{
this.switchSortedMode(false);
}
else
{
this.switchSortedMode(true);
}
if(this.goodLength>=this.goodMaxLength*2||this.badLength>this.maxExpectedLength*2)
{
this.resort();
}
if(this.sortedMode)
{
if(element.fCost<this.boundryCost)
{
this.addToGood(element);
this.openStatesSearch[element.str] = element;
}
else if(element.fCost<this.worstCost)
{
this.addToBad(element);
this.openStatesSearch[element.str] = element;
}
}
else
{
this.addToGood(element);
this.openStatesSearch[element.str] = element;
}
}
switchSortedMode(mode)
{
if(!mode&&this.sortedMode)
{
this.sortedMode = false;
for(let i = 0; this.badLength>0; i++)
{
if(this.badList[i]!=undefined)
{
this.badLength--;
this.addToGood(this.badList[i]);
}
}
this.badList = [];
this.badVacancies = [];
}
if(mode&&!this.sortedMode)
{
this.resort();
this.sortedMode = true;
}
}
addToGood(element)
{
if(this.goodVacancies.length != 0)
{
let index = this.goodVacancies.pop();
this.goodList[index] = element;
}
else
{
this.goodList.push(element);
}
this.goodLength++;
}
addToBad(element)
{
if(this.badVacancies.length != 0)
{
let index = this.badVacancies.pop();
this.badList[index] = element;
}
else
{
this.badList.push(element);
}
this.badLength++;
}
resort()
{
if(this.goodLength != 0)
{
for(let i = 0; this.goodLength>0; i++)
{
if(this.goodList[i]!=undefined)
{
this.goodLength--;
this.addToBad(this.goodList[i]);
}
}
this.goodList = [];
this.goodVacancies = [];
}
if(this.badLength > this.maxExpectedLength*2)
{
console.log("huh");
let bestOfTheWorst = new OrderedList((e)=>{
return e[0];
});
let boundry = Infinity;
let popcount = 0;
for(let i = 0; i < this.badList.length; i++)
{
if(this.badList[i] != undefined)
{
let cost = this.badList[i].fCost;
if(bestOfTheWorst.array.length < this.maxExpectedLength)
{
bestOfTheWorst.addElement([-cost,i]);
if(bestOfTheWorst.array.length == this.maxExpectedLength)
{
boundry = cost;
}
}
else if(cost<boundry)
{
bestOfTheWorst.addElement([-cost,i]);
popcount++;
let poppedId = this.badList[bestOfTheWorst.array.pop()[1]].str;
if(this.openStatesSearch[poppedId] != undefined)
{
delete this.openStatesSearch[poppedId];
}
boundry = -(bestOfTheWorst.array[this.maxExpectedLength-1][0]);
}
else
{
delete this.openStatesSearch[this.badList[i].str];
}
}
}
let transferBuffer = [];
for(let i = 0; i < this.maxExpectedLength; i++)
{
let index = bestOfTheWorst.array[i][1];
transferBuffer.push(this.badList[index]);
if(this.openStatesSearch[this.badList[index].str] == undefined)
{
this.openStatesSearch[this.badList[index].str] = this.badList[index];
}
}
this.worstCost = transferBuffer[this.maxExpectedLength-1].fCost;
this.badList = transferBuffer;
this.badLength = this.maxExpectedLength;
}
this.goodMaxLength = 2*Math.ceil(Math.sqrt(this.badLength));
let badDefragged = [];
let candidates = new OrderedList((e)=>{
return e[0];
});
this.boundryCost = Infinity;
for(let i = 0; i < this.badList.length; i++)
{
if(this.badList[i] != undefined)
{
let cost = this.badList[i].fCost;
if(candidates.array.length < this.goodMaxLength)
{
candidates.addElement([-cost,i]);
if(candidates.array.length == this.goodMaxLength)
{
this.boundryCost = -candidates.array[this.goodMaxLength-1][0];
}
}
else if(cost<this.boundryCost)
{
candidates.addElement([-cost,i]);
badDefragged.push(this.badList[candidates.array.pop()[1]]);
this.boundryCost = -(candidates.array[this.goodMaxLength-1][0]);
}
else
{
badDefragged.push(this.badList[i])
}
}
}
this.goodList = [];
for(let i = 0; i < this.goodMaxLength; i++)
{
this.goodList.push(this.badList[candidates.array[i][1]]);
}
this.goodLength = this.goodMaxLength;
this.goodVacancies = [];
this.badList = badDefragged;
this.badLength = badDefragged.length;
}
getElementByStr(str)
{
return this.openStatesSearch[str];
}
}
class STRIPS
{
constructor(stateTemplate)
{
this.actions = [];
this.heuristic = stateTemplate.heuristicFunc;
this.getStateString = stateTemplate.stateStringFunc;
}
//Adds an action to the list of possible actions
addAction(action)
{
let failed = false;
if(action.type == undefined)
{
console.warn("Action Type Invalid");
}
if(typeof(action.executeFunc) != "function")
{
console.error("Action "+action.type+": Invalid or Missing Execute Fuction")
failed= true;
}
else if(action.executeFunc.length <2)
{
console.error("Action "+action.type+": Not Enough Execute Fuction Params")
failed= true;
}
if(typeof(action.validFunc) != "function")
{
console.error("Action "+action.type+": Invalid or Missing Validation Fuction")
failed= true;
}
else if(action.validFunc.length <2)
{
console.error("Action "+action.type+": Not Enough Validation Fuction Params")
failed= true;
}
if(typeof(action.costFunc) != "function")
{
console.error("Action "+action.type+": Invalid or Missing Cost Fuction")
failed= true;
}
else if(action.costFunc.length <2)
{
console.error("Action "+action.type+": Not Enough Cost Fuction Params")
failed= true;
}
/*for(let a in action.inputs)
{
if(action.inputs[a].length == 0)
{
console.error("Action "+action.type+": Input Set "+a+" Empty")
failed= true;
}
}*/
if(!failed)
{
this.actions.push(action);
}
return !failed;
}
//Returns the valid actions for a given state
getValidActions(state)
{
//List of actions to be generated
let actions = [];
//Loops through all the different types of actions
for(let actionIndex in this.actions)
{
//Current action
let a = this.actions[actionIndex];
//Array of possible actions
let inputs = a.getInputsFunc(state);
//Array that contains the indices of the inputs that are currently being tried
let paramIndexArray = [];
for(let i in inputs)
{
paramIndexArray.push(0);
}
let complete = false;
while(!complete)
{
//Generates list of params from index array
let params = [];
for(let i in paramIndexArray)
{
params[i] = inputs[i][paramIndexArray[i]];
}
//Checks if the params result in a valid action
if(a.validFunc(state,params))
{
//If the action is valid, add it to the list of valid actions
actions.push([actionIndex,params]);
}
//Increments indices
//If index overflows past the total number of params it is reset to zero and the next index is incremented
let carry = true;
let i = 0;
while(carry)
{
//Increments the ith index
paramIndexArray[i]++;
//Check if the index has overflowed
if(paramIndexArray[i]>inputs[i].length-1)
{
//If the parameter has overflowed it is reset to zero and the next parameter is selected for incrementation
paramIndexArray[i] = 0;
//Check if this is this the last parameter
if(i<inputs.length-1)
{
//If not proceed with incrementing the next parameter
i++;
}
else
{
//If it is the last parameter that means that all possible parameters have been checked for this action and that the next action should be selected
carry = false;
complete = true;
}
}
else
{
//If it has not overflowed, incrementation is stopped
carry = false;
}
}
}
}
//Return the valid actions
return actions;
}
aStarSearch(initialState,goalState,cycleLimit,suppressErrors=false,changableInitialState,maxExpectedCycles)
{
//The node at the end of the path
let finalNode;
//If maxExpectedCycles isn't passed in it defaults to cycleLimit
if(maxExpectedCycles ==undefined)
{
maxExpectedCycles = cycleLimit;
}
//States where the cost has been calculated have not been fully explored yet
let openStates = new SemiSortedQueue(maxExpectedCycles);
//States that have been fully explored and should not be be backtracked onto
let closedStates = {};
//String representing the goal state
let goalStr = this.getStateString(goalState);
//Copy of the initial state with added info relevant to aStar
let iState;
if(changableInitialState != undefined)
{
iState = changableInitialState;
}
else
{
iState = JSON.parse(JSON.stringify(initialState));
}
//Inital costs
iState.gCost = 0;
iState.hCost = this.heuristic(iState,goalState);
iState.fCost = iState.gCost+iState.hCost;
//String representing the initial state
iState.str = this.getStateString(iState);
//Checks if the state is alread solved
if(iState.str == goalStr)
{
console.log("State Already Solved")
return [];
}
//Action taken to get to this state. This is marked is the root node by an action index of -1
iState.action = [-1];
//Adds the initial state to the open states list
openStates.addElement(iState);
let isAtGoal = false;
let counter = 0;
while(!isAtGoal&&counter<cycleLimit)
{
//The open state with the lowest cost
let bestState = openStates.getBestElement();
//As it is being explored, the best state string is added to closed states to avoid backtracking
let stateClosed = {action: bestState.action,parent:bestState.parent};
closedStates[bestState.str]=stateClosed;
//Gets all valid actions for this state
let avalibleActions = this.getValidActions(bestState);
//Loops through all avalible actions
for(let a of avalibleActions)
{
//Gets the new state based on the action
let newState = this.actions[a[0]].executeFunc(bestState,a[1]);
newState.str = this.getStateString(newState);
//Checks if it is backtracking
if(closedStates[newState.str] == undefined)
{
//If it is not backtracking, relevant data is updated and it is added to open states
//G cost is the cost of the previous state plus the cost of the action
let addedGCost = this.actions[a[0]].costFunc(newState,a[1]);
newState.gCost = bestState.gCost+addedGCost;
newState.hCost = this.heuristic(newState,goalState);
newState.fCost = newState.gCost+newState.hCost;
newState.action = a;
newState.parent = stateClosed;
//Adds the current node to the open nodes list if there is not already a more efficient node there
if(addedGCost != Infinity)
{
if(openStates.getElementByStr(newState.str) == undefined)
{
openStates.addElement(newState);
}
else
{
if(newState.fCost < openStates.getElementByStr(newState.str).fCost)
{
openStates.addElement(newState);
}
}
}
}
//Checks if the new state is at the goal
if(newState.str==goalStr)
{
//If it is at the goal, the while loop is stopped and the action list of the new state is returned
finalNode = newState;
isAtGoal = true;
}
}
counter++;
}
if(isAtGoal)
{
//Generates a list of actions from the final node
//As it moves backwards down the tree, the list of actions will be created backwards
let actionsInverted = [];
let atRoot = false;
let node = finalNode;
while(!atRoot)
{
//Checks if its at the root node
if(node.action[0] != -1)
{
//The action of the node is added to the list of actions
actionsInverted.push({
name:this.actions[node.action[0]].type,
index:node.action[0],
params:node.action[1]
});
//The node is set to its parent moving it up the tree
node = node.parent;
}
else
{
atRoot = true;
}
}
//Flips the inverted list of actions
let actions = [];
for(let i = actionsInverted.length-1; i >= 0; i--)
{
actions.push(actionsInverted[i]);
}
this.cycles = counter;
return actions;
}
else
{
if(!suppressErrors)
{
console.error("Error: Path was not found within the allowed number of steps")
}
}
}
benchmark(attempts,getRandomState,goalState,cycleLimit,logResults,cloneState,maxExpectedCycles)
{
//Statistics vars
let totalCycles = 0;
let totalActions = 0;
let totalFailures = 0;
let trueTotalAttempts = 0;
let doCloneState = cloneState != undefined;
let successTime = 0;
let failureTime = 0;
let failedStates = [];
for(let i = 0; i < attempts; i++)
{
//Actual number of total attemps (success+fail)
trueTotalAttempts++;
//Gets a random state
let randState = getRandomState();
//Gets a cloned copy of the state if the cloneState function is provided
let clonedState = undefined;
if(doCloneState)
{
if(doCloneState)
{
clonedState = cloneState(randState);
}
}
//Executes aStarSearch while timed
let startTime;
let endTime;
startTime = performance.now();
let acts = this.aStarSearch(randState,goalState,cycleLimit,true,clonedState,maxExpectedCycles);
endTime = performance.now();
//If acts is undefined then that means that aStarSearch ran out of cycles
if(acts == undefined)
{
//In the case of a failure deincrement i discarding the run
i--;
//Add to the failure count and time
totalFailures++;
failureTime+=endTime-startTime;
//Add the state to the failed states list
if(doCloneState)
{
failedStates.push(cloneState(randState));
}
else
{
failedStates.push(randState);
}
//If the number of total attempts is more than twice the allowed attemps then the loop is killed to prevent a practically infinite loop
if(trueTotalAttempts>attempts*2)
{
break;
}
}
else
{
//If the search succeeds the actions cycles and time are added
totalActions += acts.length;
totalCycles+=this.cycles;
successTime+=endTime-startTime;
}
}
//Calculates average failure time and sets the value to "No Failures" if there are no failures
let avFailTime = failureTime/totalFailures;
if(totalFailures == 0)
{
avFailTime = "No Failures";
}
//Create output object with the statistics
let output =
{
overwhelmingFailure:trueTotalAttempts>attempts*2,
averageCycles: totalCycles/attempts,
averageActions:totalActions/attempts,
averageTimeTotal:(successTime+failureTime)/trueTotalAttempts,
averageTimePerSuccess:successTime/attempts,
averageTimePerFailure:avFailTime,
cycleRunoutProbability:totalFailures/trueTotalAttempts,
failureCount:totalFailures,
failedStates:failedStates
}
//Log results
if(logResults)
{
console.log("-------- Benchmark Results --------");
console.log("\n");
console.log("Overwhelming Failure: ", output.overwhelmingFailure);
console.log("\n");
console.log("Average Number of Cycles: ", output.averageCycles);
console.log("Average Number of Actions: ", output.averageActions);
console.log("\n");
console.log("Average Time Per Attempt (ms): ", output.averageTimeTotal);
console.log("Average Time Per Successful Attempt (ms): ", output.averageTimePerSuccess);
console.log("Average Time Per Failed Attempt (ms): ", output.averageTimePerFailure);
console.log("\n");
console.log("Probability of Exceeding Max Cycles: ", output.cycleRunoutProbability*100+"%");
console.log("Number Of Failed Attempts: ", totalFailures);
console.log("-----------------------------------");
console.log("\n\n");
}
return output;
}
}