[ 
https://issues.apache.org/jira/browse/FLINK-1633?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14363234#comment-14363234
 ] 

ASF GitHub Bot commented on FLINK-1633:
---------------------------------------

Github user vasia commented on a diff in the pull request:

    https://github.com/apache/flink/pull/452#discussion_r26487167
  
    --- Diff: 
flink-staging/flink-gelly/src/main/java/org/apache/flink/graph/example/EuclideanGraphExample.java
 ---
    @@ -0,0 +1,231 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.apache.flink.graph.example;
    +
    +import org.apache.flink.api.common.ProgramDescription;
    +import org.apache.flink.api.common.functions.MapFunction;
    +import org.apache.flink.api.java.DataSet;
    +import org.apache.flink.api.java.ExecutionEnvironment;
    +import org.apache.flink.api.java.tuple.Tuple3;
    +import org.apache.flink.graph.Edge;
    +import org.apache.flink.graph.Graph;
    +import org.apache.flink.graph.Triplet;
    +import org.apache.flink.graph.Vertex;
    +import org.apache.flink.graph.example.utils.EuclideanGraphData;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Given a directed, unweighted graph, with vertex values representing 
points in a plan,
    + * return a weighted graph where the edge weights are equal to the 
Euclidean distance between the
    + * src and the trg vertex values.
    + *
    + * <p>
    + * Input files are plain text files and must be formatted as follows:
    + * <ul>
    + *         <li> Vertices are represented by their vertexIds and vertex 
values and are separated by newlines,
    + *         the value being formed of two doubles separated by a comma.
    + *         For example: <code>1,1.0,1.0\n2,2.0,2.0\n3,3.0,3.0\n</code> 
defines a data set of three vertices
    + *         <li> Edges are represented by triples of srcVertexId, 
srcEdgeId, weight which are
    + *         separated by commas. Edges themselves are separated by 
newlines. The initial edge value will be overwritten.
    + *         For example: <code>1,2,13.0\n1,3,6.0\n</code> defines two edges 
1-2 and 1-3 having
    + *         weights 13 and 6 respectively.
    + * </ul>
    + * </p>
    + *
    + * Usage <code>EuclideanDistanceExample &lt;vertex path&gt; &lt;edge 
path&gt; &lt;result path&gt;</code><br>
    + * If no parameters are provided, the program is ran with default data from
    + * {@link org.apache.flink.graph.example.utils.EuclideanGraphData}
    + */
    +@SuppressWarnings("serial")
    +public class EuclideanGraphExample implements ProgramDescription {
    +
    +   public static void main(String[] args) throws Exception {
    +
    +           if (!parseParameters(args)) {
    +                   return;
    +           }
    +
    +           ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
    +
    +           DataSet<Vertex<Long, Point>> vertices = getVerticesDataSet(env);
    +
    +           DataSet<Edge<Long, Double>> edges = getEdgesDataSet(env);
    +
    +           Graph<Long, Point, Double> graph = Graph.fromDataSet(vertices, 
edges, env);
    +
    +           DataSet<Triplet<Long, Point, Double>> triplets = 
graph.getTriplets();
    +
    +           // the edge value will be the Euclidean distance between its 
src and trg vertex
    +           DataSet<Triplet<Long, Point, Double>> resultedTriplets = 
triplets
    +                           .map(new MapFunction<Triplet<Long, Point, 
Double>, Triplet<Long, Point, Double>>() {
    +
    +                                   @Override
    +                                   public Triplet<Long, Point, Double> 
map(Triplet<Long, Point, Double> triplet) throws Exception {
    +
    +                                           Vertex<Long, Point> srcVertex = 
triplet.getSrcVertex();
    +                                           Vertex<Long, Point> trgVertex = 
triplet.getTrgVertex();
    +                                           Edge<Long, Double> edge = 
triplet.getEdge();
    +
    +                                           
edge.setValue(srcVertex.getValue().euclideanDistance(trgVertex.getValue()));
    +
    +                                           return new Triplet<Long, Point, 
Double>(srcVertex, trgVertex, edge);
    +                                   }
    +                           });
    +
    +           // retrieve the edges from the final result
    +           DataSet<Edge<Long, Double>> result = resultedTriplets
    +                           .map(new MapFunction<Triplet<Long, Point, 
Double>, Edge<Long, Double>>() {
    +
    +                                   @Override
    +                                   public Edge<Long, Double> 
map(Triplet<Long, Point, Double> triplet) throws Exception {
    +                                           return triplet.getEdge();
    +                                   }
    +                           });
    +
    +           // emit result
    +           if (fileOutput) {
    +                   result.writeAsCsv(outputPath, "\n", ",");
    +           } else {
    +                   result.print();
    +           }
    +
    +           env.execute("Euclidean Graph Example");
    +   }
    +
    +   @Override
    +   public String getDescription() {
    +           return "Weighing a graph by computing the Euclidean distance " +
    +                           "between its vertices";
    +   }
    +
    +   // 
*************************************************************************
    +   //     DATA TYPES
    +   // 
*************************************************************************
    +
    +   /**
    +    * A simple two-dimensional point.
    +    */
    +   public static class Point implements Serializable {
    +
    +           public double x, y;
    +
    +           public Point() {}
    +
    +           public Point(double x, double y) {
    +                   this.x = x;
    +                   this.y = y;
    +           }
    +
    +           public Point add(Point other) {
    --- End diff --
    
    is this used anywhere?


> Add getTriplets() Gelly method
> ------------------------------
>
>                 Key: FLINK-1633
>                 URL: https://issues.apache.org/jira/browse/FLINK-1633
>             Project: Flink
>          Issue Type: New Feature
>          Components: Gelly
>    Affects Versions: 0.9
>            Reporter: Vasia Kalavri
>            Assignee: Andra Lungu
>            Priority: Minor
>              Labels: starter
>
> In some graph algorithms, it is required to access the graph edges together 
> with the vertex values of the source and target vertices. For example, 
> several graph weighting schemes compute some kind of similarity weights for 
> edges, based on the attributes of the source and target vertices. This issue 
> proposes adding a convenience Gelly method that generates a DataSet of 
> <srcVertex, Edge, TrgVertex> triplets from the input graph.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to