diff options
author | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2019-06-13 15:29:33 -0400 |
---|---|---|
committer | 20001LastOrder <boqi.chen@mail.mcgill.ca> | 2019-06-13 15:29:33 -0400 |
commit | d40cfffcbb0a36140fe6b1e7d95d4254358863e7 (patch) | |
tree | f8d658ee489b2a7c87be33361a7cce2a67b640f8 /Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app | |
parent | Merge branch 'master' into Realistic-Generation-SURE (diff) | |
download | VIATRA-Generator-d40cfffcbb0a36140fe6b1e7d95d4254358863e7.tar.gz VIATRA-Generator-d40cfffcbb0a36140fe6b1e7d95d4254358863e7.tar.zst VIATRA-Generator-d40cfffcbb0a36140fe6b1e7d95d4254358863e7.zip |
Hill climbing for realistic graphs with consistency feature
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app')
2 files changed, 24 insertions, 5 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend index cf871ead..1745bc35 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/Main.xtend | |||
@@ -35,7 +35,7 @@ class Main { | |||
35 | 35 | ||
36 | //human input has different package declaration | 36 | //human input has different package declaration |
37 | // reader = new GraphReader(Yakindumm2PackageImpl.eINSTANCE); | 37 | // reader = new GraphReader(Yakindumm2PackageImpl.eINSTANCE); |
38 | val human = new RWInformation("inputs/Random/", "outputs/", 1); | 38 | val human = new RWInformation("inputs/Fake_Random_Random/", "outputs/", 1); |
39 | calculateAllModels(human.inputFolder, human.outputFolder,human.numRuns, reader); | 39 | calculateAllModels(human.inputFolder, human.outputFolder,human.numRuns, reader); |
40 | 40 | ||
41 | 41 | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend index cdd06027..71fa5fed 100644 --- a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/app/PartialInterpretationMetric.xtend | |||
@@ -1,5 +1,6 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app | 1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.JSDistance | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance | 4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.distance.KSDistance |
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.PartialInterpretationGraph | 5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph.PartialInterpretationGraph |
5 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter | 6 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.io.CsvFileWriter |
@@ -17,13 +18,14 @@ import org.eclipse.emf.ecore.util.EcoreUtil | |||
17 | import org.eclipse.viatra.dse.api.Solution | 18 | import org.eclipse.viatra.dse.api.Solution |
18 | 19 | ||
19 | class PartialInterpretationMetric { | 20 | class PartialInterpretationMetric { |
20 | var static state = 0; | ||
21 | var static KSDistance ks; | 21 | var static KSDistance ks; |
22 | var static JSDistance js; | ||
22 | 23 | ||
23 | def static void initPaths(){ | 24 | def static void initPaths(){ |
24 | new File("debug/metric/").mkdir(); | 25 | new File("debug/metric/").mkdir(); |
25 | new File("debug/metric/trajectories/").mkdir(); | 26 | new File("debug/metric/trajectories/").mkdir(); |
26 | ks = new KSDistance(Domain.Yakinduum); | 27 | ks = new KSDistance(Domain.Yakinduum); |
28 | js = new JSDistance(Domain.Yakinduum); | ||
27 | } | 29 | } |
28 | 30 | ||
29 | def static MetricDistanceGroup calculateMetricDistance(PartialInterpretation partial){ | 31 | def static MetricDistanceGroup calculateMetricDistance(PartialInterpretation partial){ |
@@ -35,6 +37,22 @@ class PartialInterpretationMetric { | |||
35 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, null); | 37 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, null); |
36 | var metricSamples = metricCalculator.evaluateAllMetricsToSamples(); | 38 | var metricSamples = metricCalculator.evaluateAllMetricsToSamples(); |
37 | 39 | ||
40 | var mpc = js.mpcDistance(metricSamples.mpcSamples); | ||
41 | var na = js.naDistance(metricSamples.naSamples); | ||
42 | var outDegree = js.outDegreeDistance(metricSamples.outDegreeSamples); | ||
43 | |||
44 | return new MetricDistanceGroup(mpc, na, outDegree); | ||
45 | } | ||
46 | |||
47 | def static MetricDistanceGroup calculateMetricDistanceKS(PartialInterpretation partial){ | ||
48 | val metrics = new ArrayList<Metric>(); | ||
49 | metrics.add(new OutDegreeMetric()); | ||
50 | metrics.add(new NodeActivityMetric()); | ||
51 | metrics.add(new MultiplexParticipationCoefficientMetric()); | ||
52 | |||
53 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, null); | ||
54 | var metricSamples = metricCalculator.evaluateAllMetricsToSamples(); | ||
55 | |||
38 | var mpc = ks.mpcDistance(metricSamples.mpcSamples); | 56 | var mpc = ks.mpcDistance(metricSamples.mpcSamples); |
39 | var na = ks.naDistance(metricSamples.naSamples); | 57 | var na = ks.naDistance(metricSamples.naSamples); |
40 | var outDegree = ks.outDegreeDistance(metricSamples.outDegreeSamples); | 58 | var outDegree = ks.outDegreeDistance(metricSamples.outDegreeSamples); |
@@ -52,7 +70,6 @@ class PartialInterpretationMetric { | |||
52 | //make dir since the folder can be none existing | 70 | //make dir since the folder can be none existing |
53 | new File(path).mkdir(); | 71 | new File(path).mkdir(); |
54 | val filename = path + "/state_"+currentStateId+"-"+counter+".csv"; | 72 | val filename = path + "/state_"+currentStateId+"-"+counter+".csv"; |
55 | state++; | ||
56 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, currentStateId); | 73 | val metricCalculator = new PartialInterpretationGraph(partial, metrics, currentStateId); |
57 | 74 | ||
58 | CsvFileWriter.write(metricCalculator.evaluateAllMetrics(), filename); | 75 | CsvFileWriter.write(metricCalculator.evaluateAllMetrics(), filename); |
@@ -60,20 +77,22 @@ class PartialInterpretationMetric { | |||
60 | 77 | ||
61 | def static void outputTrajectories(PartialInterpretation empty, List<Solution> solutions){ | 78 | def static void outputTrajectories(PartialInterpretation empty, List<Solution> solutions){ |
62 | for(solution : solutions){ | 79 | for(solution : solutions){ |
80 | |||
63 | //need to copy the empty solution because the transition directly worked on the graph | 81 | //need to copy the empty solution because the transition directly worked on the graph |
64 | val emptySolutionCopy = EcoreUtil.copy(empty) | 82 | val emptySolutionCopy = EcoreUtil.copy(empty) |
65 | val trajectory = solution.shortestTrajectory; | 83 | val trajectory = solution.shortestTrajectory; |
66 | trajectory.modelWithEditingDomain = emptySolutionCopy | 84 | trajectory.model = emptySolutionCopy |
67 | 85 | ||
68 | // state codes that will record the trajectory | 86 | // state codes that will record the trajectory |
69 | val stateCodes = newArrayList() | 87 | val stateCodes = newArrayList() |
70 | |||
71 | var counter = 0 | 88 | var counter = 0 |
89 | |||
72 | //transform and record the state codes for each state | 90 | //transform and record the state codes for each state |
73 | while(trajectory.doNextTransformation){ | 91 | while(trajectory.doNextTransformation){ |
74 | //println(trajectory.stateCoder.createStateCode) | 92 | //println(trajectory.stateCoder.createStateCode) |
75 | val stateId = trajectory.stateCoder.createStateCode.toString | 93 | val stateId = trajectory.stateCoder.createStateCode.toString |
76 | val interpretation = trajectory.getModel(); | 94 | val interpretation = trajectory.getModel(); |
95 | println(stateId) | ||
77 | //calculate metrics of current state | 96 | //calculate metrics of current state |
78 | calculateMetric(interpretation as PartialInterpretation, "debug/metric/output", stateId, counter) | 97 | calculateMetric(interpretation as PartialInterpretation, "debug/metric/output", stateId, counter) |
79 | stateCodes.add(stateId) | 98 | stateCodes.add(stateId) |