From 5a4ed07581a50f0fa30d78913249a89b61f612e7 Mon Sep 17 00:00:00 2001 From: Alwine Balfanz <100916390+alwba@users.noreply.github.com> Date: Wed, 10 Aug 2022 20:50:37 +0200 Subject: [PATCH] [#1559] reformat code according code style --- .../operators/metric/AvgDegreeEvolution.java | 85 ++++---- .../operators/metric/MaxDegreeEvolution.java | 85 ++++---- .../operators/metric/MinDegreeEvolution.java | 86 ++++---- .../metric/functions/AggregateType.java | 39 +++- .../functions/ExtractAllTimePointsReduce.java | 30 +-- .../GroupDegreeTreesToAggregateDegrees.java | 185 ++++++++-------- .../TransformDeltaToAbsoluteDegreeTree.java | 40 ++-- .../metric/AvgDegreeEvolutionTest.java | 204 ++++++++--------- .../metric/MaxDegreeEvolutionTest.java | 206 +++++++++--------- .../metric/MinDegreeEvolutionTest.java | 206 +++++++++--------- 10 files changed, 604 insertions(+), 562 deletions(-) diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolution.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolution.java index cd6cbd6d4e3b..c344143fafbf 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolution.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolution.java @@ -23,7 +23,12 @@ import org.gradoop.flink.model.impl.operators.sampling.functions.VertexDegree; import org.gradoop.temporal.model.api.TimeDimension; import org.gradoop.temporal.model.impl.TemporalGraph; -import org.gradoop.temporal.model.impl.operators.metric.functions.*; +import org.gradoop.temporal.model.impl.operators.metric.functions.GroupDegreeTreesToAggregateDegrees; +import org.gradoop.temporal.model.impl.operators.metric.functions.TransformDeltaToAbsoluteDegreeTree; +import org.gradoop.temporal.model.impl.operators.metric.functions.FlatMapVertexIdEdgeInterval; +import org.gradoop.temporal.model.impl.operators.metric.functions.BuildTemporalDegreeTree; +import org.gradoop.temporal.model.impl.operators.metric.functions.ExtractAllTimePointsReduce; +import org.gradoop.temporal.model.impl.operators.metric.functions.AggregateType; import java.util.Objects; import java.util.TreeMap; @@ -33,48 +38,50 @@ * whole lifetime of the graph. The average value is rounded up to the next integer. */ public class AvgDegreeEvolution - implements UnaryBaseGraphToValueOperator>> { - /** - * The time dimension that will be considered. - */ - private final TimeDimension dimension; + implements UnaryBaseGraphToValueOperator>> { + /** + * The time dimension that will be considered. + */ + private final TimeDimension dimension; - /** - * The degree type (IN, OUT, BOTH); - */ - private final VertexDegree degreeType; + /** + * The degree type (IN, OUT, BOTH); + */ + private final VertexDegree degreeType; - /** - * Creates an instance of this average degree evolution operator. - * - * @param degreeType the degree type to use (IN, OUT, BOTH). - * @param dimension the time dimension to use (VALID_TIME, TRANSACTION_TIME). - */ - public AvgDegreeEvolution(VertexDegree degreeType, TimeDimension dimension) throws RuntimeException{ - this.degreeType = Objects.requireNonNull(degreeType); - this.dimension = Objects.requireNonNull(dimension); - } + /** + * Creates an instance of this average degree evolution operator. + * + * @param degreeType the degree type to use (IN, OUT, BOTH). + * @param dimension the time dimension to use (VALID_TIME, TRANSACTION_TIME). + * + * @throws RuntimeException in case of an error. + */ + public AvgDegreeEvolution(VertexDegree degreeType, TimeDimension dimension) throws RuntimeException { + this.degreeType = Objects.requireNonNull(degreeType); + this.dimension = Objects.requireNonNull(dimension); + } - @Override - public DataSet> execute(TemporalGraph graph) { - DataSet>> absoluteDegreeTrees = graph.getEdges() - // 1) Extract vertex id(s) and corresponding time intervals - .flatMap(new FlatMapVertexIdEdgeInterval(dimension, degreeType)) - // 2) Group them by the vertex id - .groupBy(0) - // 3) For each vertex id, build a degree tree data structure - .reduceGroup(new BuildTemporalDegreeTree()) - // 4) Transform each tree to aggregated evolution - .map(new TransformDeltaToAbsoluteDegreeTree()); + @Override + public DataSet> execute(TemporalGraph graph) { + DataSet>> absoluteDegreeTrees = graph.getEdges() + // 1) Extract vertex id(s) and corresponding time intervals + .flatMap(new FlatMapVertexIdEdgeInterval(dimension, degreeType)) + // 2) Group them by the vertex id + .groupBy(0) + // 3) For each vertex id, build a degree tree data structure + .reduceGroup(new BuildTemporalDegreeTree()) + // 4) Transform each tree to aggregated evolution + .map(new TransformDeltaToAbsoluteDegreeTree()); - DataSet> timePoints = absoluteDegreeTrees - // 5) extract all timestamps where degree of any vertex changes - .reduceGroup(new ExtractAllTimePointsReduce()) - .distinct(); + DataSet> timePoints = absoluteDegreeTrees + // 5) extract all timestamps where degree of any vertex changes + .reduceGroup(new ExtractAllTimePointsReduce()) + .distinct(); - return absoluteDegreeTrees - // 6) Merge trees together and calculate aggregation - .reduceGroup(new GroupDegreeTreesToAggregateDegrees(AggregateType.AVG, timePoints)); + return absoluteDegreeTrees + // 6) Merge trees together and calculate aggregation + .reduceGroup(new GroupDegreeTreesToAggregateDegrees(AggregateType.AVG, timePoints)); - } + } } diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolution.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolution.java index 16708397d924..337b11ba602d 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolution.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolution.java @@ -23,7 +23,12 @@ import org.gradoop.flink.model.impl.operators.sampling.functions.VertexDegree; import org.gradoop.temporal.model.api.TimeDimension; import org.gradoop.temporal.model.impl.TemporalGraph; -import org.gradoop.temporal.model.impl.operators.metric.functions.*; +import org.gradoop.temporal.model.impl.operators.metric.functions.GroupDegreeTreesToAggregateDegrees; +import org.gradoop.temporal.model.impl.operators.metric.functions.TransformDeltaToAbsoluteDegreeTree; +import org.gradoop.temporal.model.impl.operators.metric.functions.FlatMapVertexIdEdgeInterval; +import org.gradoop.temporal.model.impl.operators.metric.functions.BuildTemporalDegreeTree; +import org.gradoop.temporal.model.impl.operators.metric.functions.ExtractAllTimePointsReduce; +import org.gradoop.temporal.model.impl.operators.metric.functions.AggregateType; import java.util.Objects; import java.util.TreeMap; @@ -33,48 +38,50 @@ * whole lifetime of the graph. */ public class MaxDegreeEvolution - implements UnaryBaseGraphToValueOperator>> { - /** - * The time dimension that will be considered. - */ - private final TimeDimension dimension; + implements UnaryBaseGraphToValueOperator>> { + /** + * The time dimension that will be considered. + */ + private final TimeDimension dimension; - /** - * The degree type (IN, OUT, BOTH); - */ - private final VertexDegree degreeType; + /** + * The degree type (IN, OUT, BOTH); + */ + private final VertexDegree degreeType; - /** - * Creates an instance of this maximum degree evolution operator. - * - * @param degreeType the degree type to use (IN, OUT, BOTH). - * @param dimension the time dimension to use (VALID_TIME, TRANSACTION_TIME). - */ - public MaxDegreeEvolution(VertexDegree degreeType, TimeDimension dimension) throws RuntimeException { - this.degreeType = Objects.requireNonNull(degreeType); - this.dimension = Objects.requireNonNull(dimension); - } + /** + * Creates an instance of this maximum degree evolution operator. + * + * @param degreeType the degree type to use (IN, OUT, BOTH). + * @param dimension the time dimension to use (VALID_TIME, TRANSACTION_TIME). + * + * @throws RuntimeException in case of an error. + */ + public MaxDegreeEvolution(VertexDegree degreeType, TimeDimension dimension) throws RuntimeException { + this.degreeType = Objects.requireNonNull(degreeType); + this.dimension = Objects.requireNonNull(dimension); + } - @Override - public DataSet> execute(TemporalGraph graph) { - DataSet>> absoluteDegreeTrees = graph.getEdges() - // 1) Extract vertex id(s) and corresponding time intervals - .flatMap(new FlatMapVertexIdEdgeInterval(dimension, degreeType)) - // 2) Group them by the vertex id - .groupBy(0) - // 3) For each vertex id, build a degree tree data structure - .reduceGroup(new BuildTemporalDegreeTree()) - // 4) Transform each tree to aggregated evolution - .map(new TransformDeltaToAbsoluteDegreeTree()); + @Override + public DataSet> execute(TemporalGraph graph) { + DataSet>> absoluteDegreeTrees = graph.getEdges() + // 1) Extract vertex id(s) and corresponding time intervals + .flatMap(new FlatMapVertexIdEdgeInterval(dimension, degreeType)) + // 2) Group them by the vertex id + .groupBy(0) + // 3) For each vertex id, build a degree tree data structure + .reduceGroup(new BuildTemporalDegreeTree()) + // 4) Transform each tree to aggregated evolution + .map(new TransformDeltaToAbsoluteDegreeTree()); - DataSet> timePoints = absoluteDegreeTrees - // 5) extract all timestamps where degree of any vertex changes - .reduceGroup(new ExtractAllTimePointsReduce()) - .distinct(); + DataSet> timePoints = absoluteDegreeTrees + // 5) extract all timestamps where degree of any vertex changes + .reduceGroup(new ExtractAllTimePointsReduce()) + .distinct(); - return absoluteDegreeTrees - // 6) Merge trees together and calculate aggregation - .reduceGroup(new GroupDegreeTreesToAggregateDegrees(AggregateType.AVG, timePoints)); + return absoluteDegreeTrees + // 6) Merge trees together and calculate aggregation + .reduceGroup(new GroupDegreeTreesToAggregateDegrees(AggregateType.MAX, timePoints)); - } + } } diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolution.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolution.java index 018bfc68b6c9..174345e393f0 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolution.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolution.java @@ -23,7 +23,12 @@ import org.gradoop.flink.model.impl.operators.sampling.functions.VertexDegree; import org.gradoop.temporal.model.api.TimeDimension; import org.gradoop.temporal.model.impl.TemporalGraph; -import org.gradoop.temporal.model.impl.operators.metric.functions.*; +import org.gradoop.temporal.model.impl.operators.metric.functions.GroupDegreeTreesToAggregateDegrees; +import org.gradoop.temporal.model.impl.operators.metric.functions.TransformDeltaToAbsoluteDegreeTree; +import org.gradoop.temporal.model.impl.operators.metric.functions.FlatMapVertexIdEdgeInterval; +import org.gradoop.temporal.model.impl.operators.metric.functions.BuildTemporalDegreeTree; +import org.gradoop.temporal.model.impl.operators.metric.functions.ExtractAllTimePointsReduce; +import org.gradoop.temporal.model.impl.operators.metric.functions.AggregateType; import java.util.Objects; import java.util.TreeMap; @@ -33,48 +38,49 @@ * whole lifetime of the graph. */ public class MinDegreeEvolution - implements UnaryBaseGraphToValueOperator>> { - /** - * The time dimension that will be considered. - */ - private final TimeDimension dimension; + implements UnaryBaseGraphToValueOperator>> { + /** + * The time dimension that will be considered. + */ + private final TimeDimension dimension; - /** - * The degree type (IN, OUT, BOTH); - */ - private final VertexDegree degreeType; + /** + * The degree type (IN, OUT, BOTH); + */ + private final VertexDegree degreeType; - /** - * Creates an instance of this minimum degree evolution operator. - * - * @param degreeType the degree type to use (IN, OUT, BOTH). - * @param dimension the time dimension to use (VALID_TIME, TRANSACTION_TIME). - */ - public MinDegreeEvolution(VertexDegree degreeType, TimeDimension dimension) throws RuntimeException { - this.degreeType = Objects.requireNonNull(degreeType); - this.dimension = Objects.requireNonNull(dimension); - } + /** + * Creates an instance of this minimum degree evolution operator. + * + * @param degreeType the degree type to use (IN, OUT, BOTH). + * @param dimension the time dimension to use (VALID_TIME, TRANSACTION_TIME). + * + * @throws RuntimeException in case of an error. + */ + public MinDegreeEvolution(VertexDegree degreeType, TimeDimension dimension) throws RuntimeException { + this.degreeType = Objects.requireNonNull(degreeType); + this.dimension = Objects.requireNonNull(dimension); + } - @Override - public DataSet> execute(TemporalGraph graph) { - DataSet>> absoluteDegreeTrees = graph.getEdges() - // 1) Extract vertex id(s) and corresponding time intervals - .flatMap(new FlatMapVertexIdEdgeInterval(dimension, degreeType)) - // 2) Group them by the vertex id - .groupBy(0) - // 3) For each vertex id, build a degree tree data structure - .reduceGroup(new BuildTemporalDegreeTree()) - // 4) Transform each tree to aggregated evolution - .map(new TransformDeltaToAbsoluteDegreeTree()); + @Override + public DataSet> execute(TemporalGraph graph) { + DataSet>> absoluteDegreeTrees = graph.getEdges() + // 1) Extract vertex id(s) and corresponding time intervals + .flatMap(new FlatMapVertexIdEdgeInterval(dimension, degreeType)) + // 2) Group them by the vertex id + .groupBy(0) + // 3) For each vertex id, build a degree tree data structure + .reduceGroup(new BuildTemporalDegreeTree()) + // 4) Transform each tree to aggregated evolution + .map(new TransformDeltaToAbsoluteDegreeTree()); - DataSet> timePoints = absoluteDegreeTrees - // 5) extract all timestamps where degree of any vertex changes - .reduceGroup(new ExtractAllTimePointsReduce()) - .distinct(); + DataSet> timePoints = absoluteDegreeTrees + // 5) extract all timestamps where degree of any vertex changes + .reduceGroup(new ExtractAllTimePointsReduce()) + .distinct(); - return absoluteDegreeTrees - // 6) Merge trees together and calculate aggregation - .reduceGroup(new GroupDegreeTreesToAggregateDegrees(AggregateType.AVG, timePoints)); - - } + return absoluteDegreeTrees + // 6) Merge trees together and calculate aggregation + .reduceGroup(new GroupDegreeTreesToAggregateDegrees(AggregateType.MIN, timePoints)); + } } diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/AggregateType.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/AggregateType.java index b7da36cdcb13..803758d747fe 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/AggregateType.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/AggregateType.java @@ -1,19 +1,34 @@ +/* + * Copyright © 2014 - 2021 Leipzig University (Database Research Group) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.gradoop.temporal.model.impl.operators.metric.functions; /** * Enum for defining an aggregate type. */ public enum AggregateType { - /** - * Minimum aggregation. - */ - MIN, - /** - * Maximum aggregation. - */ - MAX, - /** - * Average aggregation. - */ - AVG + /** + * Minimum aggregation. + */ + MIN, + /** + * Maximum aggregation. + */ + MAX, + /** + * Average aggregation. + */ + AVG } diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/ExtractAllTimePointsReduce.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/ExtractAllTimePointsReduce.java index ece67f4a2efd..50febde273aa 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/ExtractAllTimePointsReduce.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/ExtractAllTimePointsReduce.java @@ -30,20 +30,24 @@ */ public class ExtractAllTimePointsReduce implements GroupReduceFunction>, Tuple1> { - public ExtractAllTimePointsReduce() { + /** + * Creates an instance of the group reduce function. + */ + public ExtractAllTimePointsReduce() { + } + + @Override + public void reduce(Iterable>> iterable, + Collector> collector) throws Exception { + SortedSet timePoints = new TreeSet<>(); + + for (Tuple2> tuple : iterable) { + timePoints.addAll(tuple.f1.keySet()); } - @Override - public void reduce(Iterable>> iterable, Collector> collector) throws Exception { - SortedSet timePoints = new TreeSet<>(); - - for (Tuple2> tuple : iterable) { - timePoints.addAll(tuple.f1.keySet()); - } - - for (Long timePoint: timePoints) { - collector.collect(new Tuple1<>(timePoint)); - } - + for (Long timePoint : timePoints) { + collector.collect(new Tuple1<>(timePoint)); } + + } } diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/GroupDegreeTreesToAggregateDegrees.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/GroupDegreeTreesToAggregateDegrees.java index fc9982ff5e41..b5f019cb1c4f 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/GroupDegreeTreesToAggregateDegrees.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/GroupDegreeTreesToAggregateDegrees.java @@ -22,107 +22,114 @@ import org.apache.flink.util.Collector; import org.gradoop.common.model.impl.id.GradoopId; -import java.util.*; -import java.util.stream.Stream; +import java.util.TreeSet; +import java.util.TreeMap; +import java.util.SortedSet; +import java.util.List; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; /** * A group reduce function that merges all Tuples (vId, degreeTree) to a dataset of tuples (time, aggDegree) * that represents the aggregated degree value for the whole graph at the given time. */ public class GroupDegreeTreesToAggregateDegrees - implements GroupReduceFunction>, Tuple2> { - - /** - * The aggregate type to use (min,max,avg). - */ - private final AggregateType aggregateType; - /** - * The timestamps where at least one vertex degree changes. - */ - private final SortedSet timePoints; - - /** - * Creates an instance of this group reduce function. - * - * @param aggregateType the aggregate type to use (min,max,avg). - */ - public GroupDegreeTreesToAggregateDegrees(AggregateType aggregateType, DataSet> timePoints) { - this.aggregateType = aggregateType; - - List> tuples; - try { - tuples = timePoints.collect(); - this.timePoints = new TreeSet<>(); - - for (int i = 0; i < timePoints.count(); i = i + 1) { - this.timePoints.add(tuples.get(i).getField(0)); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - +implements GroupReduceFunction>, Tuple2> { + + /** + * The aggregate type to use (min,max,avg). + */ + private final AggregateType aggregateType; + /** + * The timestamps where at least one vertex degree changes. + */ + private final SortedSet timePoints; + + /** + * Creates an instance of this group reduce function. + * + * @param aggregateType the aggregate type to use (min,max,avg). + * @param timePoints the time points were vertex degrees change. + */ + public GroupDegreeTreesToAggregateDegrees(AggregateType aggregateType, DataSet> timePoints) { + this.aggregateType = aggregateType; + + List> tuples; + + try { + tuples = timePoints.collect(); + + this.timePoints = new TreeSet<>(); + + for (int i = 0; i < timePoints.count(); i = i + 1) { + this.timePoints.add(tuples.get(i).getField(0)); + } + } catch (Exception e) { + throw new RuntimeException(e); } + } - @Override - public void reduce(Iterable>> iterable, - Collector> collector) throws Exception { + @Override + public void reduce(Iterable>> iterable, + Collector> collector) throws Exception { - // init necessary maps and set - HashMap> degreeTrees = new HashMap<>(); - HashMap vertexDegrees = new HashMap<>(); + // init necessary maps and set + HashMap> degreeTrees = new HashMap<>(); + HashMap vertexDegrees = new HashMap<>(); + + // convert the iterables to a hashmap and remember all possible timestamps + for (Tuple2> tuple : iterable) { + degreeTrees.put(tuple.f0, tuple.f1); + } - // convert the iterables to a hashmap and remember all possible timestamps - for (Tuple2> tuple : iterable) { - degreeTrees.put(tuple.f0, tuple.f1); + int numberOfVertices = degreeTrees.size(); + + // Add default times + timePoints.add(Long.MIN_VALUE); + + for (Long timePoint : timePoints) { + // skip last default time + if (Long.MAX_VALUE == timePoint) { + continue; + } + // Iterate over all vertices + for (Map.Entry> entry : degreeTrees.entrySet()) { + // Make sure the vertex is registered in the current vertexDegrees capture + if (!vertexDegrees.containsKey(entry.getKey())) { + vertexDegrees.put(entry.getKey(), 0); } - int numberOfVertices = degreeTrees.size(); - - // Add default times - timePoints.add(Long.MIN_VALUE); - - for (Long timePoint : timePoints) { - // skip last default time - if (Long.MAX_VALUE == timePoint) { - continue; - } - // Iterate over all vertices - for (Map.Entry> entry : degreeTrees.entrySet()) { - // Make sure the vertex is registered in the current vertexDegrees capture - if (!vertexDegrees.containsKey(entry.getKey())) { - vertexDegrees.put(entry.getKey(), 0); - } - - // Check if timestamp is in tree, if not, take the lower key - if (entry.getValue().containsKey(timePoint)) { - vertexDegrees.put(entry.getKey(), entry.getValue().get(timePoint)); - } else { - Long lowerKey = entry.getValue().lowerKey(timePoint); - if (lowerKey != null) { - vertexDegrees.put(entry.getKey(), entry.getValue().get(lowerKey)); - } - } - } - - // Here, every tree with this time point is iterated. Now we need to aggregate for the current time. - Optional opt; - switch (aggregateType) { - case MIN: - opt = vertexDegrees.values().stream().reduce(Math::min); - opt.ifPresent(integer -> collector.collect(new Tuple2<>(timePoint, integer))); - break; - case MAX: - opt = vertexDegrees.values().stream().reduce(Math::max); - opt.ifPresent(integer -> collector.collect(new Tuple2<>(timePoint, integer))); - break; - case AVG: - opt = vertexDegrees.values().stream().reduce(Math::addExact); - opt.ifPresent(integer -> collector.collect( - new Tuple2<>(timePoint, (int) Math.ceil((double) integer / (double) numberOfVertices)))); - break; - default: - throw new IllegalArgumentException("Aggregate type not specified."); - } + // Check if timestamp is in tree, if not, take the lower key + if (entry.getValue().containsKey(timePoint)) { + vertexDegrees.put(entry.getKey(), entry.getValue().get(timePoint)); + } else { + Long lowerKey = entry.getValue().lowerKey(timePoint); + if (lowerKey != null) { + vertexDegrees.put(entry.getKey(), entry.getValue().get(lowerKey)); + } } + } + + // Here, every tree with this time point is iterated. Now we need to aggregate for the current time. + Optional opt; + switch (aggregateType) { + case MIN: + opt = vertexDegrees.values().stream().reduce(Math::min); + opt.ifPresent(integer -> collector.collect(new Tuple2<>(timePoint, integer))); + break; + case MAX: + opt = vertexDegrees.values().stream().reduce(Math::max); + opt.ifPresent(integer -> collector.collect(new Tuple2<>(timePoint, integer))); + break; + case AVG: + opt = vertexDegrees.values().stream().reduce(Math::addExact); + opt.ifPresent(integer -> collector.collect( + new Tuple2<>(timePoint, (int) Math.ceil((double) integer / (double) numberOfVertices)))); + break; + default: + throw new IllegalArgumentException("Aggregate type not specified."); + } } + } } diff --git a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/TransformDeltaToAbsoluteDegreeTree.java b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/TransformDeltaToAbsoluteDegreeTree.java index 85b8c1fadb2d..7fc3f16077bc 100644 --- a/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/TransformDeltaToAbsoluteDegreeTree.java +++ b/gradoop-temporal/src/main/java/org/gradoop/temporal/model/impl/operators/metric/functions/TransformDeltaToAbsoluteDegreeTree.java @@ -29,27 +29,27 @@ */ @FunctionAnnotation.ForwardedFields("f0") public class TransformDeltaToAbsoluteDegreeTree - implements MapFunction>, - Tuple2>> { + implements MapFunction>, + Tuple2>> { - /** - * To reduce object instantiations. - */ - private TreeMap absoluteDegreeTree; + /** + * To reduce object instantiations. + */ + private TreeMap absoluteDegreeTree; - @Override - public Tuple2> map( - Tuple2> vIdTreeMapTuple) throws Exception { - // init the degree and the temporal tree - int degree = 0; - absoluteDegreeTree = new TreeMap<>(); + @Override + public Tuple2> map( + Tuple2> vIdTreeMapTuple) throws Exception { + // init the degree and the temporal tree + int degree = 0; + absoluteDegreeTree = new TreeMap<>(); - // aggregate the degrees - for (Map.Entry entry : vIdTreeMapTuple.f1.entrySet()) { - degree += entry.getValue(); - absoluteDegreeTree.put(entry.getKey(), degree); - } - vIdTreeMapTuple.f1 = absoluteDegreeTree; - return vIdTreeMapTuple; + // aggregate the degrees + for (Map.Entry entry : vIdTreeMapTuple.f1.entrySet()) { + degree += entry.getValue(); + absoluteDegreeTree.put(entry.getKey(), degree); } -} \ No newline at end of file + vIdTreeMapTuple.f1 = absoluteDegreeTree; + return vIdTreeMapTuple; + } +} diff --git a/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolutionTest.java b/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolutionTest.java index 1de5171e2479..26519d5e834d 100644 --- a/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolutionTest.java +++ b/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/AvgDegreeEvolutionTest.java @@ -39,106 +39,106 @@ @RunWith(Parameterized.class) public class AvgDegreeEvolutionTest extends TemporalGradoopTestBase { - /** - * The expected in-degrees for each vertex label. - */ - private static final List> EXPECTED_IN_DEGREES = new ArrayList<>(); - /** - * The expected out-degrees for each vertex label. - */ - private static final List> EXPECTED_OUT_DEGREES = new ArrayList<>(); - /** - * The expected degrees for each vertex label. - */ - private static final List> EXPECTED_BOTH_DEGREES = new ArrayList<>(); - - static { - // IN DEGREES - EXPECTED_IN_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(4L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(6L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(7L, 1)); - - // OUT DEGREES - EXPECTED_OUT_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(4L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(6L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(7L, 1)); - - // DEGREES - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(4L, 2)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(6L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(7L, 1)); - } - - /** - * The degree type to test. - */ - @Parameterized.Parameter(0) - public VertexDegree degreeType; - - /** - * The expected degree evolution for the given type. - */ - @Parameterized.Parameter(1) - public List> expectedDegrees; - - /** - * The temporal graph to test the operator. - */ - TemporalGraph testGraph; - - /** - * The parameters to test the operator. - * - * @return three different vertex degree types with its corresponding expected degree evolution. - */ - @Parameterized.Parameters(name = "Test degree type {0}.") - public static Iterable parameters() { - return Arrays.asList( - new Object[] {VertexDegree.IN, EXPECTED_IN_DEGREES}, - new Object[] {VertexDegree.OUT, EXPECTED_OUT_DEGREES}, - new Object[] {VertexDegree.BOTH, EXPECTED_BOTH_DEGREES}); - } - - /** - * Set up the test graph and create the id-label mapping. - * - * @throws Exception in case of an error - */ - @Before - public void setUp() throws Exception { - testGraph = getTestGraphWithValues(); - Collection> idLabelCollection = new HashSet<>(); - testGraph.getVertices().map(v -> new Tuple2<>(v.getId(), v.getLabel())) - .returns(new TypeHint>() { - }).output(new LocalCollectionOutputFormat<>(idLabelCollection)); - getExecutionEnvironment().execute(); - } - - /** - * Test the avg degree evolution operator. - * - * @throws Exception in case of an error. - */ - @Test - public void testAvgDegree() throws Exception { - Collection> resultCollection = new ArrayList<>(); - - final DataSet> resultDataSet = testGraph - .callForValue(new AvgDegreeEvolution(degreeType, TimeDimension.VALID_TIME)); - - resultDataSet.output(new LocalCollectionOutputFormat<>(resultCollection)); - getExecutionEnvironment().execute(); - - assertTrue(resultCollection.containsAll(expectedDegrees)); - assertTrue(expectedDegrees.containsAll(resultCollection)); - } + /** + * The expected in-degrees for each vertex label. + */ + private static final List> EXPECTED_IN_DEGREES = new ArrayList<>(); + /** + * The expected out-degrees for each vertex label. + */ + private static final List> EXPECTED_OUT_DEGREES = new ArrayList<>(); + /** + * The expected degrees for each vertex label. + */ + private static final List> EXPECTED_BOTH_DEGREES = new ArrayList<>(); + + static { + // IN DEGREES + EXPECTED_IN_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(0L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(4L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(5L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(6L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(7L, 1)); + + // OUT DEGREES + EXPECTED_OUT_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(0L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(4L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(5L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(6L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(7L, 1)); + + // DEGREES + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(0L, 1)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(4L, 2)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(5L, 1)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(6L, 1)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(7L, 1)); + } + + /** + * The degree type to test. + */ + @Parameterized.Parameter(0) + public VertexDegree degreeType; + + /** + * The expected degree evolution for the given type. + */ + @Parameterized.Parameter(1) + public List> expectedDegrees; + + /** + * The temporal graph to test the operator. + */ + TemporalGraph testGraph; + + /** + * The parameters to test the operator. + * + * @return three different vertex degree types with its corresponding expected degree evolution. + */ + @Parameterized.Parameters(name = "Test degree type {0}.") + public static Iterable parameters() { + return Arrays.asList( + new Object[]{VertexDegree.IN, EXPECTED_IN_DEGREES}, + new Object[]{VertexDegree.OUT, EXPECTED_OUT_DEGREES}, + new Object[]{VertexDegree.BOTH, EXPECTED_BOTH_DEGREES}); + } + + /** + * Set up the test graph and create the id-label mapping. + * + * @throws Exception in case of an error + */ + @Before + public void setUp() throws Exception { + testGraph = getTestGraphWithValues(); + Collection> idLabelCollection = new HashSet<>(); + testGraph.getVertices().map(v -> new Tuple2<>(v.getId(), v.getLabel())) + .returns(new TypeHint>() { + }).output(new LocalCollectionOutputFormat<>(idLabelCollection)); + getExecutionEnvironment().execute(); + } + + /** + * Test the avg degree evolution operator. + * + * @throws Exception in case of an error. + */ + @Test + public void testAvgDegree() throws Exception { + Collection> resultCollection = new ArrayList<>(); + + final DataSet> resultDataSet = testGraph + .callForValue(new AvgDegreeEvolution(degreeType, TimeDimension.VALID_TIME)); + + resultDataSet.output(new LocalCollectionOutputFormat<>(resultCollection)); + getExecutionEnvironment().execute(); + + assertTrue(resultCollection.containsAll(expectedDegrees)); + assertTrue(expectedDegrees.containsAll(resultCollection)); + } } diff --git a/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolutionTest.java b/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolutionTest.java index f8c6befd0e16..0852bc918e2b 100644 --- a/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolutionTest.java +++ b/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MaxDegreeEvolutionTest.java @@ -39,108 +39,106 @@ @RunWith(Parameterized.class) public class MaxDegreeEvolutionTest extends TemporalGradoopTestBase { - /** - * The expected in-degrees for each vertex label. - */ - private static final List> EXPECTED_IN_DEGREES = new ArrayList<>(); - /** - * The expected out-degrees for each vertex label. - */ - private static final List> EXPECTED_OUT_DEGREES = new ArrayList<>(); - /** - * The expected degrees for each vertex label. - */ - private static final List> EXPECTED_BOTH_DEGREES = new ArrayList<>(); - - static { - // IN DEGREES - EXPECTED_IN_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(4L, 2)); //4,1 - EXPECTED_IN_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(6L, 1)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(7L, 1)); - - // OUT DEGREES - EXPECTED_OUT_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(4L, 2)); //4,1 - EXPECTED_OUT_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(6L, 1)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(7L, 1)); - - // DEGREES - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(4L, 3)); // 4,2 - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(6L, 2)); // 6,1 - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(7L, 1)); - } - - /** - * The degree type to test. - */ - @Parameterized.Parameter(0) - public VertexDegree degreeType; - - /** - * The expected degree evolution for the given type. - */ - @Parameterized.Parameter(1) - public List> expectedDegrees; - - /** - * The temporal graph to test the operator. - */ - TemporalGraph testGraph; - - /** - * The parameters to test the operator. - * - * @return three different vertex degree types with its corresponding expected degree evolution. - */ - @Parameterized.Parameters(name = "Test degree type {0}.") - public static Iterable parameters() { - return Arrays.asList( - new Object[] {VertexDegree.IN, EXPECTED_IN_DEGREES}, - new Object[] {VertexDegree.OUT, EXPECTED_OUT_DEGREES}, - new Object[] {VertexDegree.BOTH, EXPECTED_BOTH_DEGREES}); - } - - /** - * Set up the test graph and create the id-label mapping. - * - * @throws Exception in case of an error - */ - @Before - public void setUp() throws Exception { - testGraph = getTestGraphWithValues(); - Collection> idLabelCollection = new HashSet<>(); - testGraph.getVertices().map(v -> new Tuple2<>(v.getId(), v.getLabel())) - .returns(new TypeHint>() { - }).output(new LocalCollectionOutputFormat<>(idLabelCollection)); - getExecutionEnvironment().execute(); - } - - /** - * Test the max degree evolution operator. - * - * @throws Exception in case of an error. - */ - @Test - public void testMaxDegree() throws Exception { - Collection> resultCollection = new ArrayList<>(); - - final DataSet> resultDataSet = testGraph - .callForValue(new MaxDegreeEvolution(degreeType, TimeDimension.VALID_TIME)); - - resultDataSet.output(new LocalCollectionOutputFormat<>(resultCollection)); - getExecutionEnvironment().execute(); - - System.out.println(resultCollection); - - assertTrue(resultCollection.containsAll(expectedDegrees)); - assertTrue(expectedDegrees.containsAll(resultCollection)); - } + /** + * The expected in-degrees for each vertex label. + */ + private static final List> EXPECTED_IN_DEGREES = new ArrayList<>(); + /** + * The expected out-degrees for each vertex label. + */ + private static final List> EXPECTED_OUT_DEGREES = new ArrayList<>(); + /** + * The expected degrees for each vertex label. + */ + private static final List> EXPECTED_BOTH_DEGREES = new ArrayList<>(); + + static { + // IN DEGREES + EXPECTED_IN_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(0L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(4L, 2)); //4,1 + EXPECTED_IN_DEGREES.add(new Tuple2<>(5L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(6L, 1)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(7L, 1)); + + // OUT DEGREES + EXPECTED_OUT_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(0L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(4L, 2)); //4,1 + EXPECTED_OUT_DEGREES.add(new Tuple2<>(5L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(6L, 1)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(7L, 1)); + + // DEGREES + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(0L, 1)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(4L, 3)); // 4,2 + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(5L, 1)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(6L, 2)); // 6,1 + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(7L, 1)); + } + + /** + * The degree type to test. + */ + @Parameterized.Parameter(0) + public VertexDegree degreeType; + + /** + * The expected degree evolution for the given type. + */ + @Parameterized.Parameter(1) + public List> expectedDegrees; + + /** + * The temporal graph to test the operator. + */ + TemporalGraph testGraph; + + /** + * The parameters to test the operator. + * + * @return three different vertex degree types with its corresponding expected degree evolution. + */ + @Parameterized.Parameters(name = "Test degree type {0}.") + public static Iterable parameters() { + return Arrays.asList( + new Object[]{VertexDegree.IN, EXPECTED_IN_DEGREES}, + new Object[]{VertexDegree.OUT, EXPECTED_OUT_DEGREES}, + new Object[]{VertexDegree.BOTH, EXPECTED_BOTH_DEGREES}); + } + + /** + * Set up the test graph and create the id-label mapping. + * + * @throws Exception in case of an error + */ + @Before + public void setUp() throws Exception { + testGraph = getTestGraphWithValues(); + Collection> idLabelCollection = new HashSet<>(); + testGraph.getVertices().map(v -> new Tuple2<>(v.getId(), v.getLabel())) + .returns(new TypeHint>() { + }).output(new LocalCollectionOutputFormat<>(idLabelCollection)); + getExecutionEnvironment().execute(); + } + + /** + * Test the max degree evolution operator. + * + * @throws Exception in case of an error. + */ + @Test + public void testMaxDegree() throws Exception { + Collection> resultCollection = new ArrayList<>(); + + final DataSet> resultDataSet = testGraph + .callForValue(new MaxDegreeEvolution(degreeType, TimeDimension.VALID_TIME)); + + resultDataSet.output(new LocalCollectionOutputFormat<>(resultCollection)); + getExecutionEnvironment().execute(); + + assertTrue(resultCollection.containsAll(expectedDegrees)); + assertTrue(expectedDegrees.containsAll(resultCollection)); + } } diff --git a/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolutionTest.java b/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolutionTest.java index de34a600f3b5..9a7809cfe0cc 100644 --- a/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolutionTest.java +++ b/gradoop-temporal/src/test/java/org/gradoop/temporal/model/impl/operators/metric/MinDegreeEvolutionTest.java @@ -39,108 +39,106 @@ @RunWith(Parameterized.class) public class MinDegreeEvolutionTest extends TemporalGradoopTestBase { - /** - * The expected in-degrees for each vertex label. - */ - private static final List> EXPECTED_IN_DEGREES = new ArrayList<>(); - /** - * The expected out-degrees for each vertex label. - */ - private static final List> EXPECTED_OUT_DEGREES = new ArrayList<>(); - /** - * The expected degrees for each vertex label. - */ - private static final List> EXPECTED_BOTH_DEGREES = new ArrayList<>(); - - static { - // IN DEGREES - EXPECTED_IN_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_IN_DEGREES.add(new Tuple2<>(0L, 0)); //1 - EXPECTED_IN_DEGREES.add(new Tuple2<>(4L, 0)); //1 - EXPECTED_IN_DEGREES.add(new Tuple2<>(5L, 0)); //1 - EXPECTED_IN_DEGREES.add(new Tuple2<>(6L, 0)); //1 - EXPECTED_IN_DEGREES.add(new Tuple2<>(7L, 0)); //1 - - // OUT DEGREES - EXPECTED_OUT_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_OUT_DEGREES.add(new Tuple2<>(0L, 0)); //1 - EXPECTED_OUT_DEGREES.add(new Tuple2<>(4L, 0)); //1 - EXPECTED_OUT_DEGREES.add(new Tuple2<>(5L, 0)); //1 - EXPECTED_OUT_DEGREES.add(new Tuple2<>(6L, 0)); //1 - EXPECTED_OUT_DEGREES.add(new Tuple2<>(7L, 0)); //1 - - // DEGREES - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(0L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(4L, 1)); //2 - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(5L, 1)); - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(6L, 0)); //1 - EXPECTED_BOTH_DEGREES.add(new Tuple2<>(7L, 0)); //1 - } - - /** - * The degree type to test. - */ - @Parameterized.Parameter(0) - public VertexDegree degreeType; - - /** - * The expected degree evolution for the given type. - */ - @Parameterized.Parameter(1) - public List> expectedDegrees; - - /** - * The temporal graph to test the operator. - */ - TemporalGraph testGraph; - - /** - * The parameters to test the operator. - * - * @return three different vertex degree types with its corresponding expected degree evolution. - */ - @Parameterized.Parameters(name = "Test degree type {0}.") - public static Iterable parameters() { - return Arrays.asList( - new Object[] {VertexDegree.IN, EXPECTED_IN_DEGREES}, - new Object[] {VertexDegree.OUT, EXPECTED_OUT_DEGREES}, - new Object[] {VertexDegree.BOTH, EXPECTED_BOTH_DEGREES}); - } - - /** - * Set up the test graph and create the id-label mapping. - * - * @throws Exception in case of an error - */ - @Before - public void setUp() throws Exception { - testGraph = getTestGraphWithValues(); - Collection> idLabelCollection = new HashSet<>(); - testGraph.getVertices().map(v -> new Tuple2<>(v.getId(), v.getLabel())) - .returns(new TypeHint>() { - }).output(new LocalCollectionOutputFormat<>(idLabelCollection)); - getExecutionEnvironment().execute(); - } - - /** - * Test the min degree evolution operator. - * - * @throws Exception in case of an error. - */ - @Test - public void testMinDegree() throws Exception { - Collection> resultCollection = new ArrayList<>(); - - final DataSet> resultDataSet = testGraph - .callForValue(new MinDegreeEvolution(degreeType, TimeDimension.VALID_TIME)); - - resultDataSet.output(new LocalCollectionOutputFormat<>(resultCollection)); - getExecutionEnvironment().execute(); - - System.out.println(resultCollection); - - assertTrue(resultCollection.containsAll(expectedDegrees)); - assertTrue(expectedDegrees.containsAll(resultCollection)); - } + /** + * The expected in-degrees for each vertex label. + */ + private static final List> EXPECTED_IN_DEGREES = new ArrayList<>(); + /** + * The expected out-degrees for each vertex label. + */ + private static final List> EXPECTED_OUT_DEGREES = new ArrayList<>(); + /** + * The expected degrees for each vertex label. + */ + private static final List> EXPECTED_BOTH_DEGREES = new ArrayList<>(); + + static { + // IN DEGREES + EXPECTED_IN_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(0L, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(4L, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(5L, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(6L, 0)); + EXPECTED_IN_DEGREES.add(new Tuple2<>(7L, 0)); + + // OUT DEGREES + EXPECTED_OUT_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(0L, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(4L, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(5L, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(6L, 0)); + EXPECTED_OUT_DEGREES.add(new Tuple2<>(7L, 0)); + + // DEGREES + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(Long.MIN_VALUE, 0)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(0L, 0)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(4L, 1)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(5L, 0)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(6L, 0)); + EXPECTED_BOTH_DEGREES.add(new Tuple2<>(7L, 0)); + } + + /** + * The degree type to test. + */ + @Parameterized.Parameter(0) + public VertexDegree degreeType; + + /** + * The expected degree evolution for the given type. + */ + @Parameterized.Parameter(1) + public List> expectedDegrees; + + /** + * The temporal graph to test the operator. + */ + TemporalGraph testGraph; + + /** + * The parameters to test the operator. + * + * @return three different vertex degree types with its corresponding expected degree evolution. + */ + @Parameterized.Parameters(name = "Test degree type {0}.") + public static Iterable parameters() { + return Arrays.asList( + new Object[]{VertexDegree.IN, EXPECTED_IN_DEGREES}, + new Object[]{VertexDegree.OUT, EXPECTED_OUT_DEGREES}, + new Object[]{VertexDegree.BOTH, EXPECTED_BOTH_DEGREES}); + } + + /** + * Set up the test graph and create the id-label mapping. + * + * @throws Exception in case of an error + */ + @Before + public void setUp() throws Exception { + testGraph = getTestGraphWithValues(); + Collection> idLabelCollection = new HashSet<>(); + testGraph.getVertices().map(v -> new Tuple2<>(v.getId(), v.getLabel())) + .returns(new TypeHint>() { + }).output(new LocalCollectionOutputFormat<>(idLabelCollection)); + getExecutionEnvironment().execute(); + } + + /** + * Test the min degree evolution operator. + * + * @throws Exception in case of an error. + */ + @Test + public void testMinDegree() throws Exception { + Collection> resultCollection = new ArrayList<>(); + + final DataSet> resultDataSet = testGraph + .callForValue(new MinDegreeEvolution(degreeType, TimeDimension.VALID_TIME)); + + resultDataSet.output(new LocalCollectionOutputFormat<>(resultCollection)); + getExecutionEnvironment().execute(); + + assertTrue(resultCollection.containsAll(expectedDegrees)); + assertTrue(expectedDegrees.containsAll(resultCollection)); + } }