From 2c3dd3ad140dc54f1eeca6c2cb79dbc866051d0a Mon Sep 17 00:00:00 2001 From: Farzam Date: Thu, 15 Nov 2018 10:42:30 +0100 Subject: [PATCH] v0.0.2 --- conf/epos.properties | 128 +++--- license.txt | 0 pom.xml | 2 +- src/main/java/META-INF/MANIFEST.MF | 3 + src/main/java/agent/Agent.java | 0 src/main/java/agent/IterativeTreeAgent.java | 0 src/main/java/agent/ModifiableIeposAgent.java | 0 .../java/agent/MultiObjectiveIEPOSAgent.java | 1 - src/main/java/agent/Optimization.java | 0 src/main/java/agent/PlanSelector.java | 0 src/main/java/agent/TreeAgent.java | 0 src/main/java/agent/dataset/Dataset.java | 0 .../java/agent/dataset/DatasetDescriptor.java | 0 .../java/agent/dataset/DatasetShuffler.java | 9 +- .../java/agent/dataset/FileVectorDataset.java | 0 .../java/agent/dataset/GaussianDataset.java | 0 src/main/java/agent/logging/AgentLogger.java | 0 .../agent/logging/AgentLoggingProvider.java | 0 .../logging/GlobalComplexCostLogger.java | 0 .../java/agent/logging/GlobalCostLogger.java | 0 .../logging/GlobalResponseVectorLogger.java | 0 .../LocalCostMultiObjectiveLogger.java | 0 .../java/agent/logging/LoggingProvider.java | 0 .../agent/logging/PlanFrequencyLogger.java | 2 +- .../agent/logging/ReorganizationLogger.java | 0 .../agent/logging/SelectedPlanLogger.java | 0 .../java/agent/logging/TerminationLogger.java | 0 .../java/agent/logging/UnfairnessLogger.java | 0 .../java/agent/logging/VisualizerLogger.java | 408 ++++++++++++++++++ .../java/agent/logging/WeightsLogger.java | 0 .../java/agent/logging/image/ImageFile.java | 0 .../java/agent/logging/image/PngFile.java | 0 .../java/agent/logging/image/SvgFile.java | 0 .../agent/logging/image/copy/ImageFile.java | 0 .../agent/logging/image/copy/PngFile.java | 0 .../agent/logging/image/copy/SvgFile.java | 0 .../instrumentation/CustomFormatter.java | 0 .../MultiObjectiveIeposPlanSelector.java | 0 .../planselection/OptimizationFactor.java | 0 .../PlanSelectionOptimizationFunction.java | 0 ...lectionOptimizationFunctionCollection.java | 0 src/main/java/config/Configuration.java | 74 ++-- src/main/java/data/DataType.java | 0 src/main/java/data/HasValue.java | 0 src/main/java/data/Plan.java | 0 src/main/java/data/Vector.java | 0 src/main/java/data/io/VectorIO.java | 0 ...onExperiment.java => IEPOSExperiment.java} | 13 +- .../MultiObjectiveIEPOSExperiment.java | 160 ------- src/main/java/func/CostFunction.java | 0 .../func/CrossCorrelationCostFunction.java | 3 +- .../java/func/DifferentiableCostFunction.java | 0 src/main/java/func/DotCostFunction.java | 0 src/main/java/func/HasGoal.java | 0 src/main/java/func/IndexCostFunction.java | 0 src/main/java/func/MaxCostFunction.java | 0 src/main/java/func/PlanCostFunction.java | 27 +- .../java/func/PlanDiscomfortFunction.java | 0 .../java/func/PlanPreferenceFunction.java | 0 src/main/java/func/RMSECostFunction.java | 0 src/main/java/func/RSSCostFunction.java | 0 src/main/java/func/SqrDistCostFunction.java | 1 + src/main/java/func/StdDevCostFunction.java | 0 src/main/java/func/VarCostFunction.java | 0 .../ModifiableTreeArchitecture.java | 0 .../treestructure/ModifiableTreeClient.java | 0 .../treestructure/ModifiableTreeProvider.java | 0 .../treestructure/ModifiableTreeServer.java | 0 .../java/treestructure/TreeArchitecture.java | 0 .../ReorganizationConvergence.java | 0 .../ReorganizationGlobalCostReduction.java | 0 .../ReorganizationNever.java | 0 .../ReorganizationPeriodically.java | 0 .../ReorganizationStrategy.java | 0 src/main/java/util/Helper.java | 0 src/main/resources/lib/.DS_Store | Bin src/main/resources/lib/DSUtil.jar | Bin src/main/resources/lib/ProtoPeer.jar | Bin src/main/resources/lib/TreeGateway.jar | Bin .../lib/protopeer/core/1.0/core-1.0.jar | Bin .../lib/protopeer/core/1.0/core-1.0.pom | 0 .../protopeer/core/maven-metadata-local.xml | 0 .../lib/protopeer/dsutil/1.0/dsutil-1.0.jar | Bin .../lib/protopeer/dsutil/1.0/dsutil-1.0.pom | 0 .../protopeer/dsutil/maven-metadata-local.xml | 0 .../lib/protopeer/tree/1.0/tree-1.0.jar | Bin .../lib/protopeer/tree/1.0/tree-1.0.pom | 0 .../protopeer/tree/maven-metadata-local.xml | 0 src/main/resources/lib/readme-maven.txt | 0 src/test/java/tutorial/SimpleTestClass.java | 0 src/test/resources/reeadme.txt | 0 91 files changed, 521 insertions(+), 310 deletions(-) mode change 100644 => 100755 license.txt mode change 100644 => 100755 pom.xml create mode 100644 src/main/java/META-INF/MANIFEST.MF mode change 100644 => 100755 src/main/java/agent/Agent.java mode change 100644 => 100755 src/main/java/agent/IterativeTreeAgent.java mode change 100644 => 100755 src/main/java/agent/ModifiableIeposAgent.java mode change 100644 => 100755 src/main/java/agent/MultiObjectiveIEPOSAgent.java mode change 100644 => 100755 src/main/java/agent/Optimization.java mode change 100644 => 100755 src/main/java/agent/PlanSelector.java mode change 100644 => 100755 src/main/java/agent/TreeAgent.java mode change 100644 => 100755 src/main/java/agent/dataset/Dataset.java mode change 100644 => 100755 src/main/java/agent/dataset/DatasetDescriptor.java mode change 100644 => 100755 src/main/java/agent/dataset/DatasetShuffler.java mode change 100644 => 100755 src/main/java/agent/dataset/FileVectorDataset.java mode change 100644 => 100755 src/main/java/agent/dataset/GaussianDataset.java mode change 100644 => 100755 src/main/java/agent/logging/AgentLogger.java mode change 100644 => 100755 src/main/java/agent/logging/AgentLoggingProvider.java mode change 100644 => 100755 src/main/java/agent/logging/GlobalComplexCostLogger.java mode change 100644 => 100755 src/main/java/agent/logging/GlobalCostLogger.java mode change 100644 => 100755 src/main/java/agent/logging/GlobalResponseVectorLogger.java mode change 100644 => 100755 src/main/java/agent/logging/LocalCostMultiObjectiveLogger.java mode change 100644 => 100755 src/main/java/agent/logging/LoggingProvider.java mode change 100644 => 100755 src/main/java/agent/logging/PlanFrequencyLogger.java mode change 100644 => 100755 src/main/java/agent/logging/ReorganizationLogger.java mode change 100644 => 100755 src/main/java/agent/logging/SelectedPlanLogger.java mode change 100644 => 100755 src/main/java/agent/logging/TerminationLogger.java mode change 100644 => 100755 src/main/java/agent/logging/UnfairnessLogger.java create mode 100644 src/main/java/agent/logging/VisualizerLogger.java mode change 100644 => 100755 src/main/java/agent/logging/WeightsLogger.java mode change 100644 => 100755 src/main/java/agent/logging/image/ImageFile.java mode change 100644 => 100755 src/main/java/agent/logging/image/PngFile.java mode change 100644 => 100755 src/main/java/agent/logging/image/SvgFile.java mode change 100644 => 100755 src/main/java/agent/logging/image/copy/ImageFile.java mode change 100644 => 100755 src/main/java/agent/logging/image/copy/PngFile.java mode change 100644 => 100755 src/main/java/agent/logging/image/copy/SvgFile.java mode change 100644 => 100755 src/main/java/agent/logging/instrumentation/CustomFormatter.java mode change 100644 => 100755 src/main/java/agent/planselection/MultiObjectiveIeposPlanSelector.java mode change 100644 => 100755 src/main/java/agent/planselection/OptimizationFactor.java mode change 100644 => 100755 src/main/java/agent/planselection/PlanSelectionOptimizationFunction.java mode change 100644 => 100755 src/main/java/agent/planselection/PlanSelectionOptimizationFunctionCollection.java mode change 100644 => 100755 src/main/java/config/Configuration.java mode change 100644 => 100755 src/main/java/data/DataType.java mode change 100644 => 100755 src/main/java/data/HasValue.java mode change 100644 => 100755 src/main/java/data/Plan.java mode change 100644 => 100755 src/main/java/data/Vector.java mode change 100644 => 100755 src/main/java/data/io/VectorIO.java rename src/main/java/experiment/{ReorganizationExperiment.java => IEPOSExperiment.java} (92%) mode change 100644 => 100755 delete mode 100644 src/main/java/experiment/MultiObjectiveIEPOSExperiment.java mode change 100644 => 100755 src/main/java/func/CostFunction.java mode change 100644 => 100755 src/main/java/func/CrossCorrelationCostFunction.java mode change 100644 => 100755 src/main/java/func/DifferentiableCostFunction.java mode change 100644 => 100755 src/main/java/func/DotCostFunction.java mode change 100644 => 100755 src/main/java/func/HasGoal.java mode change 100644 => 100755 src/main/java/func/IndexCostFunction.java mode change 100644 => 100755 src/main/java/func/MaxCostFunction.java mode change 100644 => 100755 src/main/java/func/PlanCostFunction.java mode change 100644 => 100755 src/main/java/func/PlanDiscomfortFunction.java mode change 100644 => 100755 src/main/java/func/PlanPreferenceFunction.java mode change 100644 => 100755 src/main/java/func/RMSECostFunction.java mode change 100644 => 100755 src/main/java/func/RSSCostFunction.java mode change 100644 => 100755 src/main/java/func/SqrDistCostFunction.java mode change 100644 => 100755 src/main/java/func/StdDevCostFunction.java mode change 100644 => 100755 src/main/java/func/VarCostFunction.java mode change 100644 => 100755 src/main/java/treestructure/ModifiableTreeArchitecture.java mode change 100644 => 100755 src/main/java/treestructure/ModifiableTreeClient.java mode change 100644 => 100755 src/main/java/treestructure/ModifiableTreeProvider.java mode change 100644 => 100755 src/main/java/treestructure/ModifiableTreeServer.java mode change 100644 => 100755 src/main/java/treestructure/TreeArchitecture.java mode change 100644 => 100755 src/main/java/treestructure/reorganizationstrategies/ReorganizationConvergence.java mode change 100644 => 100755 src/main/java/treestructure/reorganizationstrategies/ReorganizationGlobalCostReduction.java mode change 100644 => 100755 src/main/java/treestructure/reorganizationstrategies/ReorganizationNever.java mode change 100644 => 100755 src/main/java/treestructure/reorganizationstrategies/ReorganizationPeriodically.java mode change 100644 => 100755 src/main/java/treestructure/reorganizationstrategies/ReorganizationStrategy.java mode change 100644 => 100755 src/main/java/util/Helper.java mode change 100644 => 100755 src/main/resources/lib/.DS_Store mode change 100644 => 100755 src/main/resources/lib/DSUtil.jar mode change 100644 => 100755 src/main/resources/lib/ProtoPeer.jar mode change 100644 => 100755 src/main/resources/lib/TreeGateway.jar mode change 100644 => 100755 src/main/resources/lib/protopeer/core/1.0/core-1.0.jar mode change 100644 => 100755 src/main/resources/lib/protopeer/core/1.0/core-1.0.pom mode change 100644 => 100755 src/main/resources/lib/protopeer/core/maven-metadata-local.xml mode change 100644 => 100755 src/main/resources/lib/protopeer/dsutil/1.0/dsutil-1.0.jar mode change 100644 => 100755 src/main/resources/lib/protopeer/dsutil/1.0/dsutil-1.0.pom mode change 100644 => 100755 src/main/resources/lib/protopeer/dsutil/maven-metadata-local.xml mode change 100644 => 100755 src/main/resources/lib/protopeer/tree/1.0/tree-1.0.jar mode change 100644 => 100755 src/main/resources/lib/protopeer/tree/1.0/tree-1.0.pom mode change 100644 => 100755 src/main/resources/lib/protopeer/tree/maven-metadata-local.xml mode change 100644 => 100755 src/main/resources/lib/readme-maven.txt mode change 100644 => 100755 src/test/java/tutorial/SimpleTestClass.java mode change 100644 => 100755 src/test/resources/reeadme.txt diff --git a/conf/epos.properties b/conf/epos.properties index f27917fa..293bae21 100755 --- a/conf/epos.properties +++ b/conf/epos.properties @@ -1,125 +1,95 @@ ### Dataset ### -#The folder name in the datasets path. -#Make sure it has no spaces, tabs or newlines -#(alphanum and underscore combination preferred) -dataset=gaussian +#The folder name in the datasets path. Make sure it has no spaces, tabs or newlines (alphanum and underscore preferred) +dataset=gaussian -### Basic epos parameters ### -# number of simulations for whole epos experiments +### Basic epos properties ### # any integer > 0 numSimulations=5 -# maximum number of iterations per simulation # any integer > 0 numIterations=40 -# number of children per node in the EPOS -# tree. The tree is always symmetric and balanced # any integer > 0 -numChildren=2 +numAgents=100 -# number of agent used for the experiment -# if it is higher than available agents in -# dataset, the maximum available agents will -# be used. # any integer > 0 -numAgents=1000 +numPlans=10 -# number of plans used per agent -# if it is higher than the available plans -# per agent, the maximum number will be used # any integer > 0 -numPlans=500 +numChildren=2 -# number of plan dimensions used from the start -# of the plan. if more than available, the maximum -# available are used. -# any integer > 0 +# exact dimensionality from the dataset planDim=100 ### Shuffle seeds ### -# initial agent structure before reorganization occurs -# any integer > 0 +# initial agent structure before reorganization occurs, any integer > 0 shuffle=0 -# path to a file containing permutation of indices -# file structure: one column integer index in each row +# path to a file containing permutation of indices, need its strucure: sphinx one column: integer index in each row shuffle_file="permutation.csv" - ### Weights of the global complex cost ### +numberOfWeights = 2 +weightsString = "0.0,0.0" +# number of weights used in EPOS cost function +# weights are in string format, separated by "," +# weight1: in multiobjective EPOS, this is alpha (in this example 0.2) # double from [0, 1], alpha + beta <= 1, unfairness -alpha=0.2 - +# weight2 in in multiobjective EPOS, this is beta (in this example 0.0) # double from [0, 1], alpha + beta <= 1, local objective -beta=0 - -# alpha*unfairness + beta*local_cost + (1-alpha-beta)*global_costs - - -### Cost Functions ### - -# Available cost function choices: -# NoGoal "MAX":max value, "VAR":variance, "STD":standard deviation, -# "INDEX": plan index value, "PREF": preference, "DISC": discomfort -# Goal Singal "SQR":square distance, "RMSE":root mean squared error, -# "RSS":residual sum of squares, "DOT":dot product, "XCORR":cross correlation - -# Suggested values : "XCORR", VAR", "RSS", "RMSE" -globalCostFunction="VAR" - -# Suggested values : "INDEX" "DISC", "PREF" -localCostFunction="INDEX" - -# "MIN-MAX", "STD", "UNIT-LENGTH", only for "RSS" cost -scaling="MIN-MAX" - - -### Goal Signal ### - -# filepath of the file containing the vector to be used as goal signal -# goal signal dimension are expected to be same as planDim, -# otherwise cropping or repetitive padding might occur -# if no path is provided, it will search for a “.target” file in the dataset folder -# if no file is found at all a zero valued goal signal will be generated -goalSignalPath=default +#a*unfairness + b*local_cost + (1-a-b)*global_costs +#avg local cost is local cost ### Reorganization strategy ### -# possible values: periodically, convergence, globalCostReduction, never. -strategy=periodically +# possible values: periodically, convergence, globalCostReduction, never. never_strategy: never does reorganization +strategy=never # any integer > 0, if "periodically" strategy is chosen periodically.reorganizationPeriod=3 -# any positive integer > 0, if convergence strategy is chosen +# any positive integer (>0), if "convergence" strategy is chosen, the iteration at which the selections will be memorized to be sued after the following reorganization convergence.memorizationOffset=5 # double from [0, 1] globalCost.reductionThreshold=0.5 -# any integer, keep same for reproducibility +# any integer. Keep the same seed to reproduce experiment results, what random permutations each strategy will explore, result reproducability strategy.reorganizationSeed=0 + + +#sphinx +goalSignalPath=default +#vector target for global response same dimensionality as plan +#filepath +globalCostFunction=VAR +# "VAR", "RSS", "RMSE", goal signal is ignored in funcitons with only global response as input, e.g. var +scaling="MIN-MAX" +# "STD", "UNIT-LENGTH", only for rss, +localCostFunction="INDEX" +# "COST", "PREF", # cost changes to discomfort + + ### Loggers ### -logger.GlobalCostLogger=true -logger.LocalCostMultiObjectiveLogger=true -logger.TerminationLogger=true -logger.SelectedPlanLogger=true -logger.GlobalResponseVectorLogger=true -logger.PlanFrequencyLogger=true -logger.UnfairnessLogger=true -logger.GlobalComplexCostLogger=true -logger.WeightsLogger=true -logger.ReorganizationLogger=true - -# Code related logger for debugging and checks please check here: -# https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html. -# For experiments "SEVERE" is preferred +logger.GlobalCostLogger = true +logger.LocalCostMultiObjectiveLogger = true +logger.TerminationLogger = true +logger.SelectedPlanLogger = true +logger.GlobalResponseVectorLogger = true +logger.PlanFrequencyLogger = true +logger.UnfairnessLogger = true +logger.GlobalComplexCostLogger = true +logger.WeightsLogger = true +logger.ReorganizationLogger = true +logger.VisualizerLogger = true + +#Code related logger for debugging and checks +# please check here https://docs.oracle.com/javase/7/docs/api/java/util/logging/Level.html. For experiments "SEVERE" is preferred logLevel="SEVERE" diff --git a/license.txt b/license.txt old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index 42eb2ab5..deaaa51c --- a/pom.xml +++ b/pom.xml @@ -209,7 +209,7 @@ - experiment.ReorganizationExperiment + experiment.IEPOSExperiment diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 00000000..cf4e3a46 --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: experiment.IEPOSExperiment + diff --git a/src/main/java/agent/Agent.java b/src/main/java/agent/Agent.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/IterativeTreeAgent.java b/src/main/java/agent/IterativeTreeAgent.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/ModifiableIeposAgent.java b/src/main/java/agent/ModifiableIeposAgent.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/MultiObjectiveIEPOSAgent.java b/src/main/java/agent/MultiObjectiveIEPOSAgent.java old mode 100644 new mode 100755 index 345c89d2..e47bbda9 --- a/src/main/java/agent/MultiObjectiveIEPOSAgent.java +++ b/src/main/java/agent/MultiObjectiveIEPOSAgent.java @@ -345,7 +345,6 @@ void processDownMessageMore(DownMessage parentMsg) { } private void aggregateExtended() { // System.out.println("EXTENDED!"); - if (this.isIterationAfterReorganization()) { for (int i = 0; i < this.children.size(); i++) { approvals.add(true); diff --git a/src/main/java/agent/Optimization.java b/src/main/java/agent/Optimization.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/PlanSelector.java b/src/main/java/agent/PlanSelector.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/TreeAgent.java b/src/main/java/agent/TreeAgent.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/dataset/Dataset.java b/src/main/java/agent/dataset/Dataset.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/dataset/DatasetDescriptor.java b/src/main/java/agent/dataset/DatasetDescriptor.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/dataset/DatasetShuffler.java b/src/main/java/agent/dataset/DatasetShuffler.java old mode 100644 new mode 100755 index cc62bec2..f7263606 --- a/src/main/java/agent/dataset/DatasetShuffler.java +++ b/src/main/java/agent/dataset/DatasetShuffler.java @@ -25,7 +25,6 @@ public class DatasetShuffler { public static int row = -1; - public static Logger log = Logger.getLogger(DatasetShuffler.class.getName()); /** * Default mapping is 0->0, 1->1, 2->2, .. @@ -62,8 +61,8 @@ public static Map getMappingByShuffling(Configuration config) long timeAfter = System.currentTimeMillis(); - log.info("Permuting time: " + ((timeAfter-timeBefore)/1000) + " seconds."); - log.info(Configuration.mapping.toString()); + System.out.println("Permuting time: " + ((timeAfter-timeBefore)/1000) + " seconds."); + System.out.println(Configuration.mapping.toString()); return Configuration.mapping; } @@ -81,7 +80,7 @@ public static Map getMappingForRepetitiveExperiments(Configura long timeAfter = System.currentTimeMillis(); - log.info("Permuting time: " + ((timeAfter-timeBefore)/1000) + " seconds."); + System.out.println("Permuting time: " + ((timeAfter-timeBefore)/1000) + " seconds."); return Configuration.mapping; } @@ -131,7 +130,7 @@ public static Map getMappingFromFile() { Logger.getLogger(DatasetShuffler.class.getName()).log(Level.SEVERE, null, e); } - //System.out.println(mapping.toString()); + System.out.println(mapping.toString()); return mapping; } diff --git a/src/main/java/agent/dataset/FileVectorDataset.java b/src/main/java/agent/dataset/FileVectorDataset.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/dataset/GaussianDataset.java b/src/main/java/agent/dataset/GaussianDataset.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/AgentLogger.java b/src/main/java/agent/logging/AgentLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/AgentLoggingProvider.java b/src/main/java/agent/logging/AgentLoggingProvider.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/GlobalComplexCostLogger.java b/src/main/java/agent/logging/GlobalComplexCostLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/GlobalCostLogger.java b/src/main/java/agent/logging/GlobalCostLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/GlobalResponseVectorLogger.java b/src/main/java/agent/logging/GlobalResponseVectorLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/LocalCostMultiObjectiveLogger.java b/src/main/java/agent/logging/LocalCostMultiObjectiveLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/LoggingProvider.java b/src/main/java/agent/logging/LoggingProvider.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/PlanFrequencyLogger.java b/src/main/java/agent/logging/PlanFrequencyLogger.java old mode 100644 new mode 100755 index f1ed67d3..e84caaf5 --- a/src/main/java/agent/logging/PlanFrequencyLogger.java +++ b/src/main/java/agent/logging/PlanFrequencyLogger.java @@ -89,7 +89,7 @@ private String internalFetching(MeasurementLog log) { allTokens.addAll(log.getTagsOfType(Token.class)); Iterator iter = allTokens.iterator(); - //System.out.println("Size is: " + allTokens.size()); +// System.out.println("Size is: " + allTokens.size()); HashMap>> perRun = new HashMap>>(); // > diff --git a/src/main/java/agent/logging/ReorganizationLogger.java b/src/main/java/agent/logging/ReorganizationLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/SelectedPlanLogger.java b/src/main/java/agent/logging/SelectedPlanLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/TerminationLogger.java b/src/main/java/agent/logging/TerminationLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/UnfairnessLogger.java b/src/main/java/agent/logging/UnfairnessLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/VisualizerLogger.java b/src/main/java/agent/logging/VisualizerLogger.java new file mode 100644 index 00000000..0c0b30ea --- /dev/null +++ b/src/main/java/agent/logging/VisualizerLogger.java @@ -0,0 +1,408 @@ +package agent.logging; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Paint; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Line2D; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TreeSet; + +import javax.imageio.ImageIO; + +import com.google.common.base.Function; + +//import org.apache.commons.collections15.Transformer; + +import agent.TreeAgent; +import agent.logging.image.ImageFile; +import agent.logging.image.PngFile; +import agent.logging.image.SvgFile; +import config.Configuration; +import data.DataType; +import data.Plan; +import edu.uci.ics.jung.algorithms.layout.Layout; +import edu.uci.ics.jung.algorithms.layout.RadialTreeLayout; +import edu.uci.ics.jung.graph.DelegateForest; +import edu.uci.ics.jung.graph.Forest; +import edu.uci.ics.jung.graph.Graph; +import edu.uci.ics.jung.graph.util.Context; +import edu.uci.ics.jung.visualization.DefaultVisualizationModel; +import edu.uci.ics.jung.visualization.VisualizationModel; +import edu.uci.ics.jung.visualization.VisualizationViewer; +import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse; +import edu.uci.ics.jung.visualization.control.ModalGraphMouse; +import edu.uci.ics.jung.visualization.decorators.DirectionalEdgeArrowTransformer; +import edu.uci.ics.jung.visualization.decorators.EdgeShape; +import edu.uci.ics.jung.visualization.util.VertexShapeFactory; +import protopeer.Finger; +import protopeer.measurement.MeasurementLog; +import protopeer.network.NetworkAddress; + +/** + * Visualizes tree structure. The color indicates the index of the selected plan. + * Darker color indicates higher index. + * + * @author jovan + * + * @param + */ +public class VisualizerLogger> extends AgentLogger> { + + public static int maxPlans = Integer.MIN_VALUE; + + public static Color[] colors = {new Color(243, 236, 245), + new Color(244, 236, 247), // 1 [1] + new Color(232, 218, 239), + new Color(219, 198, 228), + new Color(210, 180, 222), + new Color(194, 156, 211), // 2 [5] + new Color(187, 143, 206), + new Color(172, 119, 195), + new Color(165, 105, 189), + new Color(142, 68, 173), + new Color(125, 60, 152), // 3 [10] + new Color(108, 52, 131), + new Color(91, 44, 111), + new Color(74, 35, 90), + new Color(64, 8, 87), // 4 [14] + new Color(52, 4, 71) + }; + + private final double vertexSize127 = 2.8; + private final double vertexSize255 = 1; + private final double vertexSize511 = 1; + private final double vertexSize1023 = 1; + private double vertexSize = vertexSize127; + + private final Dimension size = new Dimension(1024, 1024); + private AffineTransform shapeTransform = null; + + private VertexShapeFactory shapeFactory = new VertexShapeFactory(); + private Forest graph; + private Map idx2vertex; + + private TreeSet scoreSet = new TreeSet(); + + @Override + public void init(TreeAgent agent) { } + + @Override + /** + * For now, logs the following info: + * - id as Finger + * - list of children + * - id of selected plan + * - the local cost of the selected plan as measured by the local cost function + */ + public void log(MeasurementLog log, int epoch, TreeAgent agent) { + if(agent.getIteration() == agent.getNumIterations()-1) { + double score = agent.getLocalCostFunction().calcCost(agent.getSelectedPlan()); + + for(Plan p : agent.getPossiblePlans()) { + this.scoreSet.add(agent.getLocalCostFunction().calcCost(p)); + } + + VisualizerLogger.maxPlans = Math.max(VisualizerLogger.maxPlans, agent.getPossiblePlans().size()); + + TreeNode node = new TreeNode(agent.getPeer().getFinger(), + agent.getChildren(), + agent.getSelectedPlanID(), + score, + this.run); + log.log(epoch, node, 0.0); + } + } + + private int getNumAgents(MeasurementLog log) { + return (int) (log.getTagsOfType(TreeNode.class).size() / Configuration.numSimulations); + } + + private void setVertexSize(int numAgents) { + if (numAgents <= 127) { + vertexSize = vertexSize127; + } else if (numAgents <= 255) { + vertexSize = vertexSize255; + } else if (numAgents <= 511) { + vertexSize = vertexSize511; + } else if (numAgents <= 1023) { + vertexSize = vertexSize1023; + } else { + vertexSize = vertexSize1023; + } + this.shapeTransform = AffineTransform.getScaleInstance(vertexSize, vertexSize); + } + + private void populateGraph(MeasurementLog log, int current_run) { + graph = new DelegateForest<>(); + + this.idx2vertex = new HashMap<>(); + + for (Object agentObj : log.getTagsOfType(TreeNode.class)) { + TreeNode agent = (TreeNode) agentObj; + + if(agent.run != current_run) continue; + + Vertex vertex = new Vertex(agent); + this.idx2vertex.put(agent.id.getNetworkAddress(), vertex); + graph.addVertex(vertex); + } + + int edge = 0; + for (Vertex node : graph.getVertices()) { + for (Finger f : node.agent.children) { + Vertex child = this.idx2vertex.get(f.getNetworkAddress()); + graph.addEdge(edge++, node, child); + } + } + } + + @Override + public void print(MeasurementLog log) { + int numAgents = this.getNumAgents(log); + this.setVertexSize(numAgents); + + for(int currentRun = 0; currentRun < Configuration.numSimulations; currentRun++) { + this.populateGraph(log, currentRun); + + File file = new File(Configuration.outputDirectory + "/selected-plans-graph-run-" + currentRun + ".png"); + BufferedImage image = this.getPlotImage(); + + try { + ImageIO.write(image, "png", file); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private void writeCurrentImage(VisualizationViewer viewer, File outputFile) { + ImageFile img = null; + if (outputFile.getName().endsWith(".png")) { + img = new PngFile(outputFile, viewer.getWidth(), viewer.getHeight()); + } else if (outputFile.getName().endsWith(".svg")) { + img = new SvgFile(outputFile, viewer.getWidth(), viewer.getHeight()); + } + + viewer.setDoubleBuffered(false); + viewer.getRootPane().paintComponents(img.createGraphics()); + viewer.setDoubleBuffered(true); + + img.write(); + } + + private BufferedImage getPlotImage() { + VisualizationModel model = new DefaultVisualizationModel(this.getLayout(this.graph)); + VisualizationViewer viewer = this.visualize(model); + viewer.setVisible(true); + AffineTransform at = new AffineTransform(); + at.scale(1, 1); + AffineTransformOp atOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); + + BufferedImage tmp = new BufferedImage(viewer.getWidth(), viewer.getHeight(), BufferedImage.TYPE_INT_ARGB); + BufferedImage outputImg = new BufferedImage(viewer.getWidth(), viewer.getHeight(), BufferedImage.TYPE_INT_ARGB); + + viewer.paint(tmp.getGraphics()); + outputImg = atOp.filter(tmp, outputImg); + return outputImg; + } + + /** + * Builds viewer for given graph layout. + * @param model + * @return + */ + private VisualizationViewer visualize(VisualizationModel model) { + VisualizationViewer viewer = new VisualizationViewer(model); + viewer.setPreferredSize(new Dimension(this.size.width, this.size.height)); + viewer.setSize(this.size.width, this.size.height); + viewer.setBackground(Color.white); + viewer.getRenderContext().setEdgeShapeTransformer(this.getEdgeShapeTransformer()); + viewer.getRenderContext().setEdgeArrowTransformer(this.getEdgeArrowTransformer()); + viewer.getRenderContext().setVertexFillPaintTransformer(this.getVertexFillPaintTransformer()); + viewer.getRenderContext().setVertexShapeTransformer(this.getVertexShapeTransformer()); + viewer.setGraphMouse(this.getGraphMouse()); + return viewer; + } + + /** + * Returns the type of line that will be drawn between vertices of the graph. + * - Line renders as strainght line + * - CubicCurve has shape of ~ + * @return + */ + private Function getEdgeShapeTransformer() { + return EdgeShape.line(graph); + } + + + /** + * Returns the type of arrow to be used. + * Because all 0 are passed, no arrow is printed. + * @return + */ + private Function, E>, Shape> getEdgeArrowTransformer() { + return new DirectionalEdgeArrowTransformer<>(0, 0, 0); + } + + /** + * Gets the color of each vertex. + * @return + */ + private Function getVertexFillPaintTransformer() { + return (Vertex vertex) -> { + return vertex.getMyColor(); + }; + } + + /** + * Gets the shape of each vertex: + * - Ellipse with getEllipse() + * - Rectangle with getRectangle() + * - RoundRectangle with getRoundRectangle() + * - RegularStar with getRegularStar() + * + * Note that shape is scaled! + * @return + */ + private Function getVertexShapeTransformer() { + return (Vertex vertex) -> { + Shape shape = this.shapeFactory.getEllipse(vertex); + shape = shapeTransform.createTransformedShape(shape); + return shape; + }; + } + + /** + * I actually have no idea what this thing does + * @return + */ + private VisualizationViewer.GraphMouse getGraphMouse() { + DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); + graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); + return graphMouse; + } + + /** + * Creates radial layout of vertices + * @param graph + * @return + */ + private Layout getLayout(Forest graph) { + Layout layout = new RadialTreeLayout<>(graph); + layout.setSize(size); + return layout; + } + + + public Color getColor(VisualizerLogger.TreeNode node) { + int val = node.selectedPlan; + int mapping = (val * VisualizerLogger.colors.length) / VisualizerLogger.maxPlans; + return VisualizerLogger.colors[mapping]; + } + + private class Vertex { + public final TreeNode agent; + private final Color color; + + public Vertex(TreeNode agent) { + this.agent = agent; + this.color = getColor(this.agent); + } + + public Color getMyColor() { + return this.color; + } + + @Override + public int hashCode() { + int hash = 3; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Vertex other = (Vertex) obj; + if (!Objects.equals(this.agent, other.agent)) { + return false; + } + return true; + } + } + + + /** + * This class holds all necessary information to be logged in Measurement Logger + * + * @author jovan + * + */ + private class TreeNode implements Serializable { + + public final int run; + public final Finger id; + public final List children; + public final int selectedPlan; + public final double localCost; + + public TreeNode(Finger id, List children, int selectedPlan, double localCost, int run) { + this.id = id; + this.children = children; + this.selectedPlan = selectedPlan; + this.localCost = localCost; + this.run = run; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + Objects.hashCode(this.id); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final TreeNode other = (TreeNode) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + if (!Objects.equals(this.children, other.children)) { + return false; + } + if (this.run != other.run) { + return false; + } + return true; + } + } + +} diff --git a/src/main/java/agent/logging/WeightsLogger.java b/src/main/java/agent/logging/WeightsLogger.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/image/ImageFile.java b/src/main/java/agent/logging/image/ImageFile.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/image/PngFile.java b/src/main/java/agent/logging/image/PngFile.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/image/SvgFile.java b/src/main/java/agent/logging/image/SvgFile.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/image/copy/ImageFile.java b/src/main/java/agent/logging/image/copy/ImageFile.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/image/copy/PngFile.java b/src/main/java/agent/logging/image/copy/PngFile.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/image/copy/SvgFile.java b/src/main/java/agent/logging/image/copy/SvgFile.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/logging/instrumentation/CustomFormatter.java b/src/main/java/agent/logging/instrumentation/CustomFormatter.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/planselection/MultiObjectiveIeposPlanSelector.java b/src/main/java/agent/planselection/MultiObjectiveIeposPlanSelector.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/planselection/OptimizationFactor.java b/src/main/java/agent/planselection/OptimizationFactor.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/planselection/PlanSelectionOptimizationFunction.java b/src/main/java/agent/planselection/PlanSelectionOptimizationFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/agent/planselection/PlanSelectionOptimizationFunctionCollection.java b/src/main/java/agent/planselection/PlanSelectionOptimizationFunctionCollection.java old mode 100644 new mode 100755 diff --git a/src/main/java/config/Configuration.java b/src/main/java/config/Configuration.java old mode 100644 new mode 100755 index 90914449..4236b000 --- a/src/main/java/config/Configuration.java +++ b/src/main/java/config/Configuration.java @@ -45,6 +45,7 @@ import agent.logging.SelectedPlanLogger; import agent.logging.TerminationLogger; import agent.logging.UnfairnessLogger; +import agent.logging.VisualizerLogger; import agent.logging.WeightsLogger; import agent.planselection.PlanSelectionOptimizationFunction; import agent.planselection.PlanSelectionOptimizationFunctionCollection; @@ -99,9 +100,11 @@ public class Configuration { public static int numIterations = 40; public static int numChildren = 2; + public static double numberOfWeights = 0; + public static String[] weights; public static double lambda = 0; - public double alpha = 0; - public double beta = 0; +// public double alpha = 0; +// public double beta = 0; public static int permutationID = 0; public static String permutationFile = null; @@ -268,6 +271,7 @@ public static String getWeightsPath() { return Configuration.outputDirectory + Configuration.pathDelimiter + Configuration.globalWeightsFilename; } + public void printConfiguration() { StringBuilder sb = new StringBuilder(); sb.append("CONFIGURATION:").append(System.lineSeparator()); @@ -282,8 +286,8 @@ public void printConfiguration() { sb.append("numIterations = ").append(Configuration.numIterations).append(System.lineSeparator()); sb.append("numChildren = ").append(Configuration.numChildren).append(System.lineSeparator()); sb.append("--------------").append(System.lineSeparator()); - sb.append("alpha = ").append(this.alpha).append(System.lineSeparator()); - sb.append("beta = ").append(this.beta).append(System.lineSeparator()); + sb.append("alpha = ").append(this.weights[0]).append(System.lineSeparator()); + sb.append("beta = ").append(this.weights[1]).append(System.lineSeparator()); sb.append("global cost function = ").append(Configuration.globalCostFunc.toString()) .append(System.lineSeparator()); sb.append("local cost function = ").append(Configuration.localCostFunc.toString()) @@ -362,6 +366,18 @@ public static void setUpEposBasicParams(Properties argMap, Configuration config) Configuration.numChildren = 2; } + if (argMap.get("shuffleFile") != null) { + Configuration.permutationFile = (String) argMap.get("shuffleFile"); + Configuration.mapping = config.readMapping.apply(config); + } else { + Configuration.mapping = config.generateDefaultMapping.apply(config); + Configuration.log.log(Level.WARNING, "Default agent mapping according to incremental index is applied."); + } + + if (argMap.get("shuffle") != null) { + Configuration.permutationID = Helper.clearInt((String) argMap.get("shuffle")); + Configuration.mapping = config.generateShuffledMapping.apply(config); + } } public static Configuration fromFile(String path) { @@ -378,7 +394,7 @@ public static Configuration fromFile(String path) { propertyCleanUp(argMap); setUpEposBasicParams(argMap, config); - prepareDataset(argMap, config); + prepareDataset(argMap); prepareReorganization(argMap, config); prepareCostFunctions(argMap, config); prepareLoggers(argMap, config); @@ -394,7 +410,7 @@ public static boolean checkMethodExistence(Class cl, String methodName) { return false; } } - + private static void prepareLoggers(Properties argMap, Configuration config) { if (argMap.get("logLevel") != null) { String level = (String) argMap.get("logLevel"); @@ -432,7 +448,7 @@ private static void prepareLoggers(Properties argMap, Configuration config) { String[] possLoggers = { "logger.GlobalCostLogger", "logger.LocalCostMultiObjectiveLogger", "logger.TerminationLogger", "logger.SelectedPlanLogger", "logger.GlobalResponseVectorLogger", "logger.PlanFrequencyLogger", "logger.UnfairnessLogger", "logger.GlobalComplexCostLogger", - "logger.WeightsLogger", "logger.ReorganizationLogger" }; + "logger.WeightsLogger", "logger.ReorganizationLogger", "logger.VisualizerLogger" }; Set selectedLoggers = Arrays.stream(possLoggers) .filter(key -> argMap.containsKey(key) && argMap.getProperty(key).equals("true")) @@ -441,7 +457,7 @@ private static void prepareLoggers(Properties argMap, Configuration config) { Configuration.loggers = initializeLoggers(selectedLoggers); } - public static void prepareDataset(Properties argMap, Configuration config) { + public static void prepareDataset(Properties argMap) { if (argMap.get("dataset") != null) { String dataset = (String) argMap.get("dataset"); Configuration.dataset = dataset; @@ -459,8 +475,8 @@ public static void prepareDataset(Properties argMap, Configuration config) { AtomicInteger maxPlans = new AtomicInteger(); AtomicInteger maxPlanDims = new AtomicInteger(); - log.info("Loading dataset from:\n" + datasetPath); - + System.out.println(datasetPath + " " + Files.notExists(Paths.get(datasetPath))); + Set requested = IntStream.range(0, Configuration.numAgents).boxed().collect(Collectors.toSet()); Set found = new HashSet<>(); @@ -509,37 +525,20 @@ public static void prepareDataset(Properties argMap, Configuration config) { + maxPlanDims.get()); } } - - if (argMap.get("shuffleFile") != null) { - Configuration.permutationFile = (String) argMap.get("shuffleFile"); - Configuration.mapping = config.readMapping.apply(config); - } else { - Configuration.mapping = config.generateDefaultMapping.apply(config); - Configuration.log.log(Level.WARNING, "Default agent mapping according to incremental index is applied."); - } - - if (argMap.get("shuffle") != null) { - Configuration.permutationID = Helper.clearInt((String) argMap.get("shuffle")); - Configuration.mapping = config.generateShuffledMapping.apply(config); - } } public static void prepareCostFunctions(Properties argMap, Configuration config) { Reflections reflections = new Reflections("func"); - if (argMap.get("alpha") != null) { - config.alpha = Double.parseDouble(Helper.clearNumericString((String) argMap.get("alpha"))); - } else { - Configuration.log.log(Level.WARNING, "Default value for alpha = 0"); - config.alpha = 0; - } + weights = new String[Integer.parseInt(argMap.get("numberOfWeights").toString())]; + + if (argMap.get("weightsString") != null) { + String[] inputWeight = argMap.get("weightsString").toString().split(","); + for (int i = 0;i> allClasses = reflections.getSubTypesOf(PlanCostFunction.class); @@ -553,7 +552,6 @@ public static void prepareCostFunctions(Properties argMap, Configuration config) // TODO Auto-generated catch block e.printStackTrace(); return null; - } }).collect(Collectors.toMap(c -> c.getLabel(), c -> c)); @@ -610,7 +608,7 @@ public static void prepareCostFunctions(Properties argMap, Configuration config) } } - + public static void prepareReorganization(Properties argMap, Configuration config) { if (argMap.get("strategy").equals("periodically")) { config.reorganizationStrategy = ReorganizationStrategyType.PERIODICALLY; @@ -730,6 +728,7 @@ public static Set initializeLoggers(Set selectedLoggers) { Configuration.getGlobalComplexCostPath()); WeightsLogger WLogger = new WeightsLogger(Configuration.getWeightsPath()); ReorganizationLogger RLogger = new ReorganizationLogger(Configuration.getReorganizationPath()); + VisualizerLogger VLogger = new VisualizerLogger(); GCLogger.setRun(Configuration.permutationID); LCLogger.setRun(Configuration.permutationID); @@ -741,10 +740,11 @@ public static Set initializeLoggers(Set selectedLoggers) { GCXLogger.setRun(Configuration.permutationID); WLogger.setRun(Configuration.permutationID); RLogger.setRun(Configuration.permutationID); + VLogger.setRun(Configuration.permutationID); Map result = Arrays .stream(new AgentLogger[] { GCLogger, LCLogger, TLogger, SPLogger, GRVLogger, DstLogger, ULogger, - GCXLogger, WLogger, RLogger }) + GCXLogger, WLogger, RLogger, VLogger }) .collect(Collectors.toMap(a -> a.getClass().getSimpleName(), a -> a)); Set res = new HashSet<>(); diff --git a/src/main/java/data/DataType.java b/src/main/java/data/DataType.java old mode 100644 new mode 100755 diff --git a/src/main/java/data/HasValue.java b/src/main/java/data/HasValue.java old mode 100644 new mode 100755 diff --git a/src/main/java/data/Plan.java b/src/main/java/data/Plan.java old mode 100644 new mode 100755 diff --git a/src/main/java/data/Vector.java b/src/main/java/data/Vector.java old mode 100644 new mode 100755 diff --git a/src/main/java/data/io/VectorIO.java b/src/main/java/data/io/VectorIO.java old mode 100644 new mode 100755 diff --git a/src/main/java/experiment/ReorganizationExperiment.java b/src/main/java/experiment/IEPOSExperiment.java old mode 100644 new mode 100755 similarity index 92% rename from src/main/java/experiment/ReorganizationExperiment.java rename to src/main/java/experiment/IEPOSExperiment.java index e73951a8..a21a865f --- a/src/main/java/experiment/ReorganizationExperiment.java +++ b/src/main/java/experiment/IEPOSExperiment.java @@ -36,7 +36,7 @@ * @author Jovan N., Thomas Asikis * */ -public class ReorganizationExperiment { +public class IEPOSExperiment { public static void runSimulation(int numChildren, // number of children for each middle node int numIterations, // total number of iterations to run for @@ -76,7 +76,7 @@ public Peer createPeer(int peerIndex, Experiment e) { private static void runOneSimulation(Configuration config, Function createAgent) { long timeBefore = System.currentTimeMillis(); - ReorganizationExperiment.runSimulation(Configuration.numChildren, Configuration.numIterations, + IEPOSExperiment.runSimulation(Configuration.numChildren, Configuration.numIterations, Configuration.numAgents, createAgent, config); long timeAfter = System.currentTimeMillis(); System.out.println("IEPOS Finished! It took: " + ((timeAfter - timeBefore) / 1000) + " seconds."); @@ -84,7 +84,7 @@ private static void runOneSimulation(Configuration config, Function> loggingProvider = new LoggingProvider<>(); for (AgentLogger logger : config.loggers) { @@ -145,14 +146,14 @@ public static void main(String[] args) { ModifiableIeposAgent newAgent = new ModifiableIeposAgent(config, possiblePlans, agentLP); - newAgent.setUnfairnessWeight(config.alpha); - newAgent.setLocalCostWeight(config.beta); + newAgent.setUnfairnessWeight(Double.parseDouble(config.weights[0])); + newAgent.setLocalCostWeight(Double.parseDouble(config.weights[1])); newAgent.setPlanSelector(planSelector); return newAgent; }; - ReorganizationExperiment.runOneSimulation(config, createAgent); + IEPOSExperiment.runOneSimulation(config, createAgent); } loggingProvider.print(); diff --git a/src/main/java/experiment/MultiObjectiveIEPOSExperiment.java b/src/main/java/experiment/MultiObjectiveIEPOSExperiment.java deleted file mode 100644 index f61846a4..00000000 --- a/src/main/java/experiment/MultiObjectiveIEPOSExperiment.java +++ /dev/null @@ -1,160 +0,0 @@ -package experiment; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.function.Function; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.Logger; - -import agent.Agent; -import agent.MultiObjectiveIEPOSAgent; -import agent.PlanSelector; -import agent.logging.AgentLogger; -import agent.logging.AgentLoggingProvider; -import agent.logging.instrumentation.CustomFormatter; -import agent.logging.LoggingProvider; -import agent.planselection.MultiObjectiveIeposPlanSelector; -import config.Configuration; -import data.Plan; -import data.Vector; -import protopeer.Experiment; -import protopeer.Peer; -import protopeer.PeerFactory; -import protopeer.SimulatedExperiment; -import protopeer.util.quantities.Time; -import treestructure.TreeArchitecture; - -/** - * This class describes multi-objective optimization with I-EPOS. It is a class with a subset of capabilities of the {@code ReorganizationExperiment} class, - * so it is preffered to use that one! - * - * @author Jovan N., Thomas Asikis - * - */ -@Deprecated -public class MultiObjectiveIEPOSExperiment { - - private static void runSimulation(int numChildren, // number of children for each middle node - int numIterations, // total number of iterations to run for - int numAgents, // total number of nodes in the network - Function createAgent, // lambda expression that creates an agent - Configuration config) { - - SimulatedExperiment experiment = new SimulatedExperiment() { - }; - TreeArchitecture architecture = new TreeArchitecture(); - - Experiment.initEnvironment(); - experiment.init(); - - PeerFactory peerFactory = new PeerFactory() { - - @Override - public Peer createPeer(int peerIndex, Experiment e) { - Agent newAgent = createAgent.apply(peerIndex); - Peer newPeer = new Peer(peerIndex); - - architecture.addPeerlets(newPeer, newAgent, peerIndex, numAgents); - - return newPeer; - } - }; - - Logger rootLogger = LogManager.getLogManager().getLogger(""); - rootLogger.setLevel(Configuration.loggingLevel); - - for (Handler h : rootLogger.getHandlers()) { - h.setLevel(Configuration.loggingLevel); - h.setFormatter(new CustomFormatter()); - } - - experiment.initPeers(0, numAgents, peerFactory); - experiment.startPeers(0, numAgents); - experiment.runSimulation(Time.inSeconds(3 + numIterations)); - } - - private static void runOneSimulation(Configuration config, Function createAgent) { - long timeBefore = System.currentTimeMillis(); - MultiObjectiveIEPOSExperiment.runSimulation(Configuration.numChildren, Configuration.numIterations, - Configuration.numAgents, createAgent, config); - long timeAfter = System.currentTimeMillis(); - System.out.println("IEPOS Finished! It took: " + ((timeAfter - timeBefore) / 1000) + " seconds."); - } - - public static void main(String[] args) { - Logger log = Logger.getLogger(MultiObjectiveIEPOSExperiment.class.getName()); - - String confPath = null; - - if (args.length > 0) { - Path pathURI = Paths.get(args[0]); - - if (!Files.notExists(pathURI) && Files.isRegularFile(pathURI)) { - log.log(Level.INFO, "Configuration file path provided from command line, " - + "overriding default conf location and using file in: \n" + pathURI.toString()); - confPath = pathURI.toString(); - } - - } - - String rootPath = System.getProperty("user.dir"); - - confPath = confPath == null ? rootPath + File.separator + "conf" + File.separator + "epos.properties" - : confPath; - - Configuration config = Configuration.fromFile(confPath); - LoggingProvider> loggingProvider = new LoggingProvider<>(); - - for (int sim = 0; sim < Configuration.numSimulations; sim++) { - - System.out.println("Simulation " + (sim + 1)); - - final int simulationId = sim; - config.permutationSeed = sim; - - for (AgentLogger al : loggingProvider.getLoggers()) { - al.setRun(sim); - } - - if (Configuration.numSimulations > 1 && sim > 0) { - Configuration.mapping = config.generateMappingForRepetitiveExperiments.apply(config); - } - - PlanSelector, Vector> planSelector = new MultiObjectiveIeposPlanSelector(); - - /** - * Function that creates an Agent given the id of it's vertex in tree graph. - * First type is input argument, second type is type of return value. - */ - Function createAgent = agentIdx -> { - - List> possiblePlans = config.getDataset(Configuration.dataset) - .getPlans(Configuration.mapping.get(agentIdx)); - - AgentLoggingProvider> agentLP = loggingProvider - .getAgentLoggingProvider(agentIdx, simulationId); - - MultiObjectiveIEPOSAgent newAgent = new MultiObjectiveIEPOSAgent( - Configuration.numIterations, possiblePlans, Configuration.globalCostFunc, - Configuration.localCostFunc, agentLP, config.simulationSeed); - - newAgent.setUnfairnessWeight(config.alpha); - newAgent.setLocalCostWeight(config.beta); - newAgent.setPlanSelector(planSelector); - return newAgent; - - }; - - MultiObjectiveIEPOSExperiment.runOneSimulation(config, createAgent); - } - - config.printConfiguration(); - // loggingProvider.print(); ~ print the results of each loggers - } - -} diff --git a/src/main/java/func/CostFunction.java b/src/main/java/func/CostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/CrossCorrelationCostFunction.java b/src/main/java/func/CrossCorrelationCostFunction.java old mode 100644 new mode 100755 index 0bf687f6..6cae6f48 --- a/src/main/java/func/CrossCorrelationCostFunction.java +++ b/src/main/java/func/CrossCorrelationCostFunction.java @@ -2,7 +2,6 @@ import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.math3.complex.Complex; import config.Configuration; @@ -179,7 +178,7 @@ static Map scale(Map translated) { @Override public Vector calcGradient(Vector value) { - logger.log(Level.WARNING, "No gradient is implement for cross-correlation cost function!"); + System.out.println("I DON'T HAVE GRADIENT IMPLEMENTED."); return null; } diff --git a/src/main/java/func/DifferentiableCostFunction.java b/src/main/java/func/DifferentiableCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/DotCostFunction.java b/src/main/java/func/DotCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/HasGoal.java b/src/main/java/func/HasGoal.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/IndexCostFunction.java b/src/main/java/func/IndexCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/MaxCostFunction.java b/src/main/java/func/MaxCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/PlanCostFunction.java b/src/main/java/func/PlanCostFunction.java old mode 100644 new mode 100755 index d9fbea92..6e38af42 --- a/src/main/java/func/PlanCostFunction.java +++ b/src/main/java/func/PlanCostFunction.java @@ -9,31 +9,22 @@ import data.DataType; /** - * A cost functionfunction that operates on a plan to calculate a scalar real - * value. + * A cost functionfunction that operates on a plan to calculate a scalar real value. * * @author Peter, Thomas Asikis - * @param - * the type of the data this cost function should handle + * @param the type of the data this cost function should handle */ public interface PlanCostFunction> { - + /** - * This method takes as an input any plan of type V and calculates the real - * number that represents the cost of the plan. This function is used during the - * minimization. - * + * This method takes as an input any plan of type V and calculates the + * real number that represents the cost of the plan. This function is used during + * the minimization. * @param plan * @return */ - public double calcCost(Plan plan); - - /** - * Registers the function in the configuration, via reflection, so that it can - * be directly called from the conf file. - * - * @return - */ - public abstract String getLabel(); + public double calcCost(Plan plan); + + public abstract String getLabel(); } diff --git a/src/main/java/func/PlanDiscomfortFunction.java b/src/main/java/func/PlanDiscomfortFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/PlanPreferenceFunction.java b/src/main/java/func/PlanPreferenceFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/RMSECostFunction.java b/src/main/java/func/RMSECostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/RSSCostFunction.java b/src/main/java/func/RSSCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/SqrDistCostFunction.java b/src/main/java/func/SqrDistCostFunction.java old mode 100644 new mode 100755 index d91c6aa0..a4531cb9 --- a/src/main/java/func/SqrDistCostFunction.java +++ b/src/main/java/func/SqrDistCostFunction.java @@ -72,6 +72,7 @@ public void populateGoalSignal() { @Override public String getLabel() { + // TODO Auto-generated method stub return "SQR"; } } diff --git a/src/main/java/func/StdDevCostFunction.java b/src/main/java/func/StdDevCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/func/VarCostFunction.java b/src/main/java/func/VarCostFunction.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/ModifiableTreeArchitecture.java b/src/main/java/treestructure/ModifiableTreeArchitecture.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/ModifiableTreeClient.java b/src/main/java/treestructure/ModifiableTreeClient.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/ModifiableTreeProvider.java b/src/main/java/treestructure/ModifiableTreeProvider.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/ModifiableTreeServer.java b/src/main/java/treestructure/ModifiableTreeServer.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/TreeArchitecture.java b/src/main/java/treestructure/TreeArchitecture.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/reorganizationstrategies/ReorganizationConvergence.java b/src/main/java/treestructure/reorganizationstrategies/ReorganizationConvergence.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/reorganizationstrategies/ReorganizationGlobalCostReduction.java b/src/main/java/treestructure/reorganizationstrategies/ReorganizationGlobalCostReduction.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/reorganizationstrategies/ReorganizationNever.java b/src/main/java/treestructure/reorganizationstrategies/ReorganizationNever.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/reorganizationstrategies/ReorganizationPeriodically.java b/src/main/java/treestructure/reorganizationstrategies/ReorganizationPeriodically.java old mode 100644 new mode 100755 diff --git a/src/main/java/treestructure/reorganizationstrategies/ReorganizationStrategy.java b/src/main/java/treestructure/reorganizationstrategies/ReorganizationStrategy.java old mode 100644 new mode 100755 diff --git a/src/main/java/util/Helper.java b/src/main/java/util/Helper.java old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/.DS_Store b/src/main/resources/lib/.DS_Store old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/DSUtil.jar b/src/main/resources/lib/DSUtil.jar old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/ProtoPeer.jar b/src/main/resources/lib/ProtoPeer.jar old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/TreeGateway.jar b/src/main/resources/lib/TreeGateway.jar old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/core/1.0/core-1.0.jar b/src/main/resources/lib/protopeer/core/1.0/core-1.0.jar old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/core/1.0/core-1.0.pom b/src/main/resources/lib/protopeer/core/1.0/core-1.0.pom old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/core/maven-metadata-local.xml b/src/main/resources/lib/protopeer/core/maven-metadata-local.xml old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/dsutil/1.0/dsutil-1.0.jar b/src/main/resources/lib/protopeer/dsutil/1.0/dsutil-1.0.jar old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/dsutil/1.0/dsutil-1.0.pom b/src/main/resources/lib/protopeer/dsutil/1.0/dsutil-1.0.pom old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/dsutil/maven-metadata-local.xml b/src/main/resources/lib/protopeer/dsutil/maven-metadata-local.xml old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/tree/1.0/tree-1.0.jar b/src/main/resources/lib/protopeer/tree/1.0/tree-1.0.jar old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/tree/1.0/tree-1.0.pom b/src/main/resources/lib/protopeer/tree/1.0/tree-1.0.pom old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/protopeer/tree/maven-metadata-local.xml b/src/main/resources/lib/protopeer/tree/maven-metadata-local.xml old mode 100644 new mode 100755 diff --git a/src/main/resources/lib/readme-maven.txt b/src/main/resources/lib/readme-maven.txt old mode 100644 new mode 100755 diff --git a/src/test/java/tutorial/SimpleTestClass.java b/src/test/java/tutorial/SimpleTestClass.java old mode 100644 new mode 100755 diff --git a/src/test/resources/reeadme.txt b/src/test/resources/reeadme.txt old mode 100644 new mode 100755