Skip to content
Permalink
Browse files

Adapt algorithm event system to be serializable (#138)

* Add initial version of new event system

* Add changes to restore functionality of NodeInfoPlugin

* Restore functionality of SearchRolloutHistogramPlugin

* Fix bug in SearchRolloutHistogramPlugin

Fixed a bug in the SearchRolloutHistogramPlugin which caused the search
rollout histogram not to update properly if a node without evaluations
was selected.

* Restore functionality of SolutionPerformanceTimelinePlugin

* Change NodeInfo to improve serialization capability

* Restore functionality of OutOfSampleErrorPlotPlugin

* Restore functionality of HASCOModelStatisticsPlugin

* Adapt existing examples according to visualization changes

* Adapt MLPlanARFFExample according to new changes

* Add equals and hashCode methods to several event history classes

* Improve AlgorithmEventHistorySerializerTest

* Add MLPlanAlgorithmEventHistorySerializationTest

* Fix sonarqube issues

* Remove useless line from build.gradle

* Fix several warnings

* Add documentation to many important classes of the GUI system

* Add documentation to more classes.

* Renamed project into jaicore-algorithminspector
  • Loading branch information...
ahetzer authored and fmohr committed Jul 8, 2019
1 parent 4e7824c commit 17978a3cdb5554135a5e69c3d672f1e0ac901a65
Showing with 3,727 additions and 2,024 deletions.
  1. +78 −79 JAICore/{jaicore-graphvisualizer → jaicore-algorithminspector}/build.gradle
  2. 0 JAICore/{jaicore-graphvisualizer → jaicore-algorithminspector}/conf/heatmap.css
  3. 0 JAICore/{jaicore-graphvisualizer → jaicore-algorithminspector}/conf/searchgraph.css
  4. +23 −24 ...icore-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/IntegerAxisFormatter.java
  5. 0 ...re-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/GraphEvent.java
  6. 0 ...minspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/GraphInitializedEvent.java
  7. 0 ...lgorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/NodeAddedEvent.java
  8. 0 ...minspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/NodeParentSwitchEvent.java
  9. 0 ...orithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/NodeRemovedEvent.java
  10. 0 ...thminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/NodeTypeSwitchEvent.java
  11. 0 ...minspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/bus/AlgorithmEventBus.java
  12. 0 ...ector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/bus/AlgorithmEventListener.java
  13. 0 ...spector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/bus/AlgorithmEventSource.java
  14. 0 ...src/main/java/ai/libs/jaicore/graphvisualizer/events/graph/bus/HandleAlgorithmEventException.java
  15. 0 ...orithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/gui/DefaultGUIEventBus.java
  16. 0 ...aicore-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/gui/GUIEvent.java
  17. 0 ...ore-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/gui/GUIEventBus.java
  18. 0 ...lgorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/gui/GUIEventListener.java
  19. 0 ...-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/gui/GUIEventSource.java
  20. 0 ...icore-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/events/gui/Histogram.java
  21. +138 −0 ...nspector/src/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistory.java
  22. +89 −0 ...tor/src/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistoryEntry.java
  23. +37 −24 ...ain/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistoryEntryDeliverer.java
  24. +79 −0 .../src/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistoryRecorder.java
  25. +78 −0 ...rc/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistorySerializer.java
  26. +10 −0 ...java/ai/libs/jaicore/graphvisualizer/events/recorder/property/AlgorithmEventPropertyComputer.java
  27. +27 −0 .../ai/libs/jaicore/graphvisualizer/events/recorder/property/PropertyComputationFailedException.java
  28. +37 −0 ...libs/jaicore/graphvisualizer/events/recorder/property/PropertyProcessedAlgorithmEventHistory.java
  29. +9 −0 ...ibs/jaicore/graphvisualizer/events/recorder/property/PropertyProcessedAlgorithmEventListener.java
  30. +8 −0 .../libs/jaicore/graphvisualizer/events/recorder/property/PropertyProcessedAlgorithmEventSource.java
  31. +3 −3 ...re-algorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/ASimpleMVCPlugin.java
  32. +6 −6 ...hminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/ASimpleMVCPluginController.java
  33. 0 ...gorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/ASimpleMVCPluginModel.java
  34. +1 −0 ...lgorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/ASimpleMVCPluginView.java
  35. +58 −0 ...e/jaicore-algorithminspector/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPlugin.java
  36. +17 −0 ...algorithminspector/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPluginController.java
  37. +11 −0 ...core-algorithminspector/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPluginModel.java
  38. +32 −0 ...icore-algorithminspector/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPluginView.java
  39. 0 ...ector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/MVCInitializationFailedException.java
  40. +3 −3 ...spector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/ControlBarGUIPlugin.java
  41. +2 −2 ...rc/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/ControlBarGUIPluginController.java
  42. 0 ...or}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/ControlBarGUIPluginModel.java
  43. 0 ...tor}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/ControlBarGUIPluginView.java
  44. 0 ...gorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/PauseEvent.java
  45. 0 ...lgorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/PlayEvent.java
  46. 0 ...gorithminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/controlbar/ResetEvent.java
  47. +1 −1 ...inspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/GraphMouseListener.java
  48. +2 −2 ...thminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/GraphViewPlugin.java
  49. +89 −0 ...tor/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/GraphViewPluginController.java
  50. +6 −6 ...spector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/GraphViewPluginModel.java
  51. 0 ...nspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/GraphViewPluginView.java
  52. +3 −3 ...hminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/NodeClickedEvent.java
  53. 0 ...rc/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/ViewGraphManipulationException.java
  54. +43 −0 ...i/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeDisplayInfoAlgorithmEventPropertyComputer.java
  55. +105 −0 ...re-algorithminspector/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfo.java
  56. +72 −0 .../java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoAlgorithmEventPropertyComputer.java
  57. +10 −10 ...hminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGUIPlugin.java
  58. +37 −0 ...or/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGUIPluginController.java
  59. +48 −0 ...spector/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGUIPluginModel.java
  60. +8 −11 ...spector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGUIPluginView.java
  61. 0 ...hminspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGenerator.java
  62. +69 −0 ...i/libs/jaicore/graphvisualizer/plugin/solutionperformanceplotter/ScoredSolutionCandidateInfo.java
  63. +45 −0 .../plugin/solutionperformanceplotter/ScoredSolutionCandidateInfoAlgorithmEventPropertyComputer.java
  64. +6 −0 .../libs/jaicore/graphvisualizer/plugin/solutionperformanceplotter/SolutionCandidateRepresenter.java
  65. 0 .../jaicore/graphvisualizer/plugin/solutionperformanceplotter/SolutionPerformanceTimelinePlugin.java
  66. +53 −0 ...raphvisualizer/plugin/solutionperformanceplotter/SolutionPerformanceTimelinePluginController.java
  67. +6 −5 ...ore/graphvisualizer/plugin/solutionperformanceplotter/SolutionPerformanceTimelinePluginModel.java
  68. +1 −0 ...core/graphvisualizer/plugin/solutionperformanceplotter/SolutionPerformanceTimelinePluginView.java
  69. 0 ...inspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/speedslider/ChangeSpeedEvent.java
  70. +3 −3 ...ector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/speedslider/SpeedSliderGUIPlugin.java
  71. +2 −2 .../main/java/ai/libs/jaicore/graphvisualizer/plugin/speedslider/SpeedSliderGUIPluginController.java
  72. 0 ...}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/speedslider/SpeedSliderGUIPluginModel.java
  73. 0 ...r}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/speedslider/SpeedSliderGUIPluginView.java
  74. 0 ...inspector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/timeslider/GoToTimeStepEvent.java
  75. +3 −3 ...spector}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/timeslider/TimeSliderGUIPlugin.java
  76. +2 −2 ...rc/main/java/ai/libs/jaicore/graphvisualizer/plugin/timeslider/TimeSliderGUIPluginController.java
  77. 0 ...or}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/timeslider/TimeSliderGUIPluginModel.java
  78. 0 ...tor}/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/timeslider/TimeSliderGUIPluginView.java
  79. +52 −6 ...inspector}/src/main/java/ai/libs/jaicore/graphvisualizer/window/AlgorithmVisualizationWindow.java
  80. +72 −0 ...est/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistorySerializerTest.java
  81. +150 −0 ...a/ai/libs/jaicore/basic/algorithm/events/serializable/DefaultPropertyProcessedAlgorithmEvent.java
  82. +76 −0 ...ain/java/ai/libs/jaicore/basic/algorithm/events/serializable/PropertyProcessedAlgorithmEvent.java
  83. +0 −70 ...sualizer/src/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistory.java
  84. +0 −23 ...zer/src/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistoryEntry.java
  85. +0 −28 .../src/main/java/ai/libs/jaicore/graphvisualizer/events/recorder/AlgorithmEventHistoryRecorder.java
  86. +0 −19 JAICore/jaicore-graphvisualizer/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPlugin.java
  87. +0 −8 ...re-graphvisualizer/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPluginController.java
  88. +0 −5 ...jaicore-graphvisualizer/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPluginModel.java
  89. +0 −12 .../jaicore-graphvisualizer/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/IGUIPluginView.java
  90. +0 −71 ...zer/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/graphview/GraphViewPluginController.java
  91. +0 −31 ...er/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGUIPluginController.java
  92. +0 −30 ...ualizer/src/main/java/ai/libs/jaicore/graphvisualizer/plugin/nodeinfo/NodeInfoGUIPluginModel.java
  93. +0 −45 ...raphvisualizer/plugin/solutionperformanceplotter/SolutionPerformanceTimelinePluginController.java
  94. +1 −1 JAICore/jaicore-ml/build.gradle
  95. +1 −1 JAICore/jaicore-planning/build.gradle
  96. +1 −1 JAICore/jaicore-search/build.gradle
  97. +71 −0 ...aicore-search/src/main/java/ai/libs/jaicore/search/gui/plugins/rollouthistograms/RolloutInfo.java
  98. +45 −0 .../libs/jaicore/search/gui/plugins/rollouthistograms/RolloutInfoAlgorithmEventPropertyComputer.java
  99. +11 −11 .../main/java/ai/libs/jaicore/search/gui/plugins/rollouthistograms/SearchRolloutHistogramPlugin.java
  100. +12 −12 .../ai/libs/jaicore/search/gui/plugins/rollouthistograms/SearchRolloutHistogramPluginController.java
  101. +15 −13 .../java/ai/libs/jaicore/search/gui/plugins/rollouthistograms/SearchRolloutHistogramPluginModel.java
  102. +4 −4 ...n/java/ai/libs/jaicore/search/gui/plugins/rollouthistograms/SearchRolloutHistogramPluginView.java
  103. +10 −1 ...re/jaicore-search/src/test/java/ai/libs/jaicore/search/testproblems/cannibals/CannibalTester.java
  104. +1 −1 build.gradle
  105. +1 −1 settings.gradle
  106. +1 −1 softwareconfiguration/hasco/build.gradle
  107. +18 −4 ...tion/hasco/src/example/java/ai/libs/hasco/examples/HASCOModelStatisticsObserverPluginExample.java
  108. +16 −2 ...sco/src/example/java/ai/libs/hasco/examples/HASCOWithSolutionPerformanceVisualizationExample.java
  109. +37 −0 ...econfiguration/hasco/src/main/java/ai/libs/hasco/gui/statsplugin/ComponentInstanceSerializer.java
  110. +31 −34 ...tion/hasco/src/main/java/ai/libs/hasco/gui/statsplugin/HASCOModelStatisticsComponentSelector.java
  111. +11 −6 ...ation/hasco/src/main/java/ai/libs/hasco/gui/statsplugin/HASCOModelStatisticsPluginController.java
  112. +37 −20 ...figuration/hasco/src/main/java/ai/libs/hasco/gui/statsplugin/HASCOModelStatisticsPluginModel.java
  113. +22 −23 ...nfiguration/hasco/src/main/java/ai/libs/hasco/gui/statsplugin/HASCOModelStatisticsPluginView.java
  114. +34 −0 ...guration/hasco/src/main/java/ai/libs/hasco/gui/statsplugin/HASCOSolutionCandidateRepresenter.java
  115. +6 −0 softwareconfiguration/hasco/src/main/java/ai/libs/hasco/model/CategoricalParameterDomain.java
  116. +296 −262 softwareconfiguration/hasco/src/main/java/ai/libs/hasco/model/Component.java
  117. +285 −267 softwareconfiguration/hasco/src/main/java/ai/libs/hasco/model/ComponentInstance.java
  118. +8 −0 softwareconfiguration/hasco/src/main/java/ai/libs/hasco/model/NumericParameterDomain.java
  119. +8 −0 softwareconfiguration/hasco/src/main/java/ai/libs/hasco/model/Parameter.java
  120. +95 −82 softwareconfiguration/mlplan/src/example/java/ai/libs/automl/mlplan/examples/MLPlanARFFExample.java
  121. +97 −84 ...onfiguration/mlplan/src/example/java/ai/libs/automl/mlplan/examples/MLPlanSubsamplingExample.java
  122. +97 −84 softwareconfiguration/mlplan/src/example/java/ai/libs/mlplan/examples/MLPlanSubsamplingExample.java
  123. +82 −71 ...iguration/mlplan/src/example/java/ai/libs/mlplan/examples/multilabel/meka/ML2PlanARFFExample.java
  124. +255 −242 ...n/mlplan/src/example/java/ai/libs/mlplan/examples/multilabel/meka/ML2PlanAutoMLCExperimenter.java
  125. +17 −4 softwareconfiguration/mlplan/src/main/java/ai/libs/mlplan/cli/MLPlanCLI.java
  126. +51 −30 ...lplan/src/main/java/ai/libs/mlplan/gui/outofsampleplots/OutOfSampleErrorPlotPluginController.java
  127. +4 −3 ...ion/mlplan/src/main/java/ai/libs/mlplan/gui/outofsampleplots/OutOfSampleErrorPlotPluginModel.java
  128. +1 −0 ...tion/mlplan/src/main/java/ai/libs/mlplan/gui/outofsampleplots/OutOfSampleErrorPlotPluginView.java
  129. +35 −0 ...src/main/java/ai/libs/mlplan/gui/outofsampleplots/WekaClassifierSolutionCandidateRepresenter.java
  130. +232 −222 ...configuration/mlplan/src/main/java/ai/libs/mlplan/multiclass/wekamlplan/MLPlanWekaClassifier.java
  131. +68 −0 ...nfiguration/mlplan/src/test/java/ai/libs/automl/MLPlanAlgorithmEventHistorySerializationTest.java
@@ -1,80 +1,79 @@
plugins {
id 'java'
id 'eclipse'
//id 'application'
//id 'org.openjfx.javafxplugin' version '0.0.5'
}
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
}
dependencies {
compile project(":JAICore:jaicore-basic")

compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'

implementation 'com.github.mwever:gs-core:2.0.2-synchrofix'
implementation 'com.github.graphstream:gs-ui-javafx:2.0-alpha'
implementation 'com.github.graphstream:gs-algo:2.0-alpha'

}
//javafx {
// modules = [ 'javafx.controls', 'javafx.swing', 'javafx.web' ]
//}
uploadArchives {
repositories {
mavenDeployer {
def ossrhUsername = project.hasProperty('ossrhUsername') ? project.property('ossrhUsername') : ""
def ossrhPassword = project.hasProperty('ossrhPassword') ? project.property('ossrhPassword') : ""

beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

pom.project {
name 'JAICore-Graphvisualizer'
packaging 'jar'
// optionally artifactId can be defined here
description 'Thist project provides a graphical interface for visualizing algorithms (especially search and AutoML algorithms) contained in AILibs.'
url 'https://libs.ai'

scm {
connection 'scm:git:https://github.com/fmohr/AILibs.git'
developerConnection 'scm:git:https://github.com/fmohr/AILibs.git'
url 'https://github.com/fmohr/AILibs'
}

licenses {
license {
name 'GPLv3'
url 'https://www.gnu.org/licenses/gpl-3.0.en.html'
}
}

developers {
developer {
id 'fmohr'
name 'Felix Mohr'
email 'felix.mohr@upb.de'
}
developer {
id 'mwever'
name 'Marcel Wever'
email 'marcel.wever@upb.de'
}
developer {
id 'ahetzer'
name 'Alexander Tornede'
email 'alexander.tornede@upb.de'
}
}
}
}
}
plugins {
id 'java'
id 'eclipse'
//id 'org.openjfx.javafxplugin' version '0.0.5'
}
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
}
dependencies {
compile project(":JAICore:jaicore-basic")

compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'

implementation 'com.github.mwever:gs-core:2.0.2-synchrofix'
implementation 'com.github.graphstream:gs-ui-javafx:2.0-alpha'
implementation 'com.github.graphstream:gs-algo:2.0-alpha'

}
//javafx {
// modules = [ 'javafx.controls', 'javafx.swing', 'javafx.web' ]
//}
uploadArchives {
repositories {
mavenDeployer {
def ossrhUsername = project.hasProperty('ossrhUsername') ? project.property('ossrhUsername') : ""
def ossrhPassword = project.hasProperty('ossrhPassword') ? project.property('ossrhPassword') : ""

beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

pom.project {
name 'JAICore-Graphvisualizer'
packaging 'jar'
// optionally artifactId can be defined here
description 'Thist project provides a graphical interface for visualizing algorithms (especially search and AutoML algorithms) contained in AILibs.'
url 'https://libs.ai'

scm {
connection 'scm:git:https://github.com/fmohr/AILibs.git'
developerConnection 'scm:git:https://github.com/fmohr/AILibs.git'
url 'https://github.com/fmohr/AILibs'
}

licenses {
license {
name 'GPLv3'
url 'https://www.gnu.org/licenses/gpl-3.0.en.html'
}
}

developers {
developer {
id 'fmohr'
name 'Felix Mohr'
email 'felix.mohr@upb.de'
}
developer {
id 'mwever'
name 'Marcel Wever'
email 'marcel.wever@upb.de'
}
developer {
id 'ahetzer'
name 'Alexander Tornede'
email 'alexander.tornede@upb.de'
}
}
}
}
}
}
@@ -1,24 +1,23 @@
package ai.libs.jaicore.graphvisualizer;

import ai.libs.jaicore.basic.MathExt;
import javafx.util.StringConverter;

public class IntegerAxisFormatter extends StringConverter<Number> {

@Override
public String toString(final Number object) {
Double val = MathExt.round(object.doubleValue(), 8);
if (val.intValue() == val) { // consider all numbers that are close to an integer by 10^-8 as ints
String str = String.valueOf(val);
str = str.substring(0, str.indexOf('.'));
return str;
} else {
return "";
}
}

@Override
public Number fromString(final String string) {
return null; // not needed
}
}
package ai.libs.jaicore.graphvisualizer;

import ai.libs.jaicore.basic.MathExt;
import javafx.util.StringConverter;

public class IntegerAxisFormatter extends StringConverter<Number> {

@Override
public String toString(final Number object) {
Double val = MathExt.round(object.doubleValue(), 8);
if (val.intValue() == val) { // consider all numbers that are close to an integer by 10^-8 as ints
String str = String.valueOf(val);
str = str.substring(0, str.indexOf('.'));
return str;
}
return "";
}

@Override
public Number fromString(final String string) {
return null; // not needed
}
}
@@ -0,0 +1,138 @@
package ai.libs.jaicore.graphvisualizer.events.recorder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringJoiner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ai.libs.jaicore.basic.ILoggingCustomizable;
import ai.libs.jaicore.basic.algorithm.IAlgorithm;
import ai.libs.jaicore.basic.algorithm.events.serializable.PropertyProcessedAlgorithmEvent;

/**
* An {@link AlgorithmEventHistory} stores {@link AlgorithmEventHistoryEntry}s constructed from {@link PropertyProcessedAlgorithmEvent}s representing the recorded behavior of an {@link IAlgorithm}. Such an {@link AlgorithmEventHistory} can
* be stored and loaded using an
* {@link AlgorithmEventHistorySerializer}.
*
* @author atornede
*
*/
public class AlgorithmEventHistory implements ILoggingCustomizable, Serializable {

private static final long serialVersionUID = 8500970353937357648L;

private transient Logger logger = LoggerFactory.getLogger(AlgorithmEventHistory.class);
private transient String loggerName;

private List<AlgorithmEventHistoryEntry> entries;

/**
* Creates a new {@link AlgorithmEventHistory}.
*/
public AlgorithmEventHistory() {
this.entries = Collections.synchronizedList(new ArrayList<>());
}

/**
* Creates a new {@link AlgorithmEventHistory} with the given {@link List} of {@link AlgorithmEventHistoryEntry}s.
*
* @param algorithmEventHistoryEntries The list of {@link AlgorithmEventHistoryEntry}s to be stored in the history.
*/
public AlgorithmEventHistory(List<AlgorithmEventHistoryEntry> algorithmEventHistoryEntries) {
this();
for (AlgorithmEventHistoryEntry entry : algorithmEventHistoryEntries) {
entries.add(entry);
}
}

/**
* Adds the given {@link PropertyProcessedAlgorithmEvent} to this {@link AlgorithmEventHistoryEntry}.
*
* @param propertyProcessedAlgorithmEvent The {@link PropertyProcessedAlgorithmEvent} to be added to this history.
*/
public void addEvent(final PropertyProcessedAlgorithmEvent propertyProcessedAlgorithmEvent) {
AlgorithmEventHistoryEntry entry = this.generateHistoryEntry(propertyProcessedAlgorithmEvent);
this.entries.add(entry);
this.logger.debug("Added entry {} for algorithm event {} to history at position {}.", entry, propertyProcessedAlgorithmEvent, this.entries.size() - 1);
}

private AlgorithmEventHistoryEntry generateHistoryEntry(final PropertyProcessedAlgorithmEvent propertyProcessedAlgorithmEvent) {
return new AlgorithmEventHistoryEntry(propertyProcessedAlgorithmEvent, this.getCurrentReceptionTime());
}

private long getCurrentReceptionTime() {
return System.currentTimeMillis();
}

/**
* Returns the {@link AlgorithmEventHistoryEntry} at the given timestep.
*
* @param timestep The timestep for which the {@link AlgorithmEventHistoryEntry} has to be returned.
* @return The {@link AlgorithmEventHistoryEntry} at the given timestep.
*/
public AlgorithmEventHistoryEntry getEntryAtTimeStep(final int timestep) {
return this.entries.get(timestep);
}

public long getLength() {
return this.entries.size();
}

@Override
public String getLoggerName() {
return this.loggerName;
}

@Override
public void setLoggerName(final String name) {
this.loggerName = name;
this.logger.info("Switching logger name to {}", name);
this.logger = LoggerFactory.getLogger(name);
this.logger.info("Switched logger name to {}", name);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((entries == null) ? 0 : entries.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AlgorithmEventHistory other = (AlgorithmEventHistory) obj;
if (entries == null) {
if (other.entries != null) {
return false;
}
} else if (!entries.equals(other.entries)) {
return false;
}
return true;
}

@Override
public String toString() {
String header = "AlgorithmEventHistory \n";
StringJoiner joiner = new StringJoiner("\n");
for (AlgorithmEventHistoryEntry entry : entries) {
joiner.add(entry.toString());
}
return header + joiner.toString();
}

}

0 comments on commit 17978a3

Please sign in to comment.
You can’t perform that action at this time.