Beginner question - sum multiple edges

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Beginner question - sum multiple edges

Kaepke, Marc
Hi,

how can I sum and reduce multiple edges in my entire graph?

e.g. my input graph looks like (source-ID, target-ID, value):
(1, 2, 30)
(1, 2, 10)
(2, 1, 55)

And I need:
(1, 2, 40)
(2, 1, 55)


Thanks!
Marc
Reply | Threaded
Open this post in threaded view
|

Re: Beginner question - sum multiple edges

Gábor Gévay
Hello Marc,

You can group by edge, and then sum:

edges
  .groupBy(0,1) // make first two fields a composite key
  .sum(2); // sum the value field

This will turn multiple edges that have the same source and target
into one edge, whose value will be the sum of the values of the
original group of edges.

Best,
Gabor

PS.: Sorry for the duplicate email, I accidentally sent my previous
email only to you instead of the mailing list.




On Mon, Apr 17, 2017 at 5:46 PM, Kaepke, Marc
<[hidden email]> wrote:

> Hi,
>
> how can I sum and reduce multiple edges in my entire graph?
>
> e.g. my input graph looks like (source-ID, target-ID, value):
> (1, 2, 30)
> (1, 2, 10)
> (2, 1, 55)
>
> And I need:
> (1, 2, 40)
> (2, 1, 55)
>
>
> Thanks!
> Marc
Reply | Threaded
Open this post in threaded view
|

Re: Beginner question - sum multiple edges

Kaepke, Marc
Hi Gábor,

thanks a lot

Best,
Marc

> Am 17.04.2017 um 20:32 schrieb Gábor Gévay <[hidden email]>:
>
> Hello Marc,
>
> You can group by edge, and then sum:
>
> edges
>  .groupBy(0,1) // make first two fields a composite key
>  .sum(2); // sum the value field
>
> This will turn multiple edges that have the same source and target
> into one edge, whose value will be the sum of the values of the
> original group of edges.
>
> Best,
> Gabor
>
> PS.: Sorry for the duplicate email, I accidentally sent my previous
> email only to you instead of the mailing list.
>
>
>
>
> On Mon, Apr 17, 2017 at 5:46 PM, Kaepke, Marc
> <[hidden email]> wrote:
>> Hi,
>>
>> how can I sum and reduce multiple edges in my entire graph?
>>
>> e.g. my input graph looks like (source-ID, target-ID, value):
>> (1, 2, 30)
>> (1, 2, 10)
>> (2, 1, 55)
>>
>> And I need:
>> (1, 2, 40)
>> (2, 1, 55)
>>
>>
>> Thanks!
>> Marc

Reply | Threaded
Open this post in threaded view
|

Re: Beginner question - sum multiple edges

Kaepke, Marc
Hi Gábor and anyone else ;-) ,

I need your help again.

My goal is a graph without self-loops and sum all edge values between two vertices into one single edge (both direction).
e.g. my input graph is described by:
1 2 10
1 2 10
2 1 10
1 1 1
1 3 5

The result has to be:
1 2 30 (sum and reduce all edges between vertex 1 and 2. I don’t care about the direction of these vertices because of the setDirection(EdgeDirection.ALL) parameter)
1 3 5


My intermediate result is:
1 2 20
2 1 10
1 3 5
with the following transformations:

ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
parameters.setDirection(EdgeDirection.ALL);

// reduce multi edges
Graph networkSumMultiEdges = Graph.fromTupleDataSet(inputGraph.getEdges().groupBy(0, 1).sum(2), ExecutionEnvironment.getExecutionEnvironment());
// reduce self-looping
Graph networkGraph = new Simplify<>().run(networkSumMultiEdges);

How can I reduce and combine (1 2 20) and (2 1 10) to one Tuple?


Best regards
Marc


Am 17.04.2017 um 21:47 schrieb Kaepke, Marc <[hidden email]>:

Hi Gábor,

thanks a lot

Best,
Marc

Am 17.04.2017 um 20:32 schrieb Gábor Gévay <[hidden email]>:

Hello Marc,

You can group by edge, and then sum:

edges
.groupBy(0,1) // make first two fields a composite key
.sum(2); // sum the value field

This will turn multiple edges that have the same source and target
into one edge, whose value will be the sum of the values of the
original group of edges.

Best,
Gabor

PS.: Sorry for the duplicate email, I accidentally sent my previous
email only to you instead of the mailing list.




On Mon, Apr 17, 2017 at 5:46 PM, Kaepke, Marc
<[hidden email]> wrote:
Hi,

how can I sum and reduce multiple edges in my entire graph?

e.g. my input graph looks like (source-ID, target-ID, value):
(1, 2, 30)
(1, 2, 10)
(2, 1, 55)

And I need:
(1, 2, 40)
(2, 1, 55)


Thanks!
Marc


Reply | Threaded
Open this post in threaded view
|

Re: Beginner question - sum multiple edges

Gábor Gévay
Hi Marc,

You can do such a map on your edges dataset that switches the
direction of edges if the source id is bigger than the target id. So
your MapFunction will have an if, which checks whether the source id
is bigger than the target id, and if it is bigger, than returns the
edge reversed, else returns the edge unchanged.

So the result of this on your example would be:
1 2 10
1 2 10
1 2 10  // This is the switched edge
1 1 1
1 3 5

You can remove loops with a filter, after which you get:
1 2 10
1 2 10
1 2 10
1 3 5

And after this, my original solution (.groupBy(0, 1).sum(2)) should
work, and give you:
1 2 30
1 3 5

Note, that my above solution is not using Gelly, so you don't need
parameters.setDirection(EdgeDirection.ALL).
I'm not sure whether there is a more simple solution that uses Gelly.

Best,
Gábor




On Sun, Apr 23, 2017 at 4:56 PM, Kaepke, Marc
<[hidden email]> wrote:

> Hi Gábor and anyone else ;-) ,
>
> I need your help again.
>
> My goal is a graph without self-loops and sum all edge values between two
> vertices into one single edge (both direction).
> e.g. my input graph is described by:
> 1 2 10
> 1 2 10
> 2 1 10
> 1 1 1
> 1 3 5
>
> The result has to be:
> 1 2 30 (sum and reduce all edges between vertex 1 and 2. I don’t care about
> the direction of these vertices because of the
> setDirection(EdgeDirection.ALL) parameter)
> 1 3 5
>
>
> My intermediate result is:
> 1 2 20
> 2 1 10
> 1 3 5
> with the following transformations:
>
> ScatterGatherConfiguration parameters = new ScatterGatherConfiguration();
> parameters.setDirection(EdgeDirection.ALL);
>
> // reduce multi edges
> Graph networkSumMultiEdges =
> Graph.fromTupleDataSet(inputGraph.getEdges().groupBy(0, 1).sum(2),
> ExecutionEnvironment.getExecutionEnvironment());
> // reduce self-looping
> Graph networkGraph = new Simplify<>().run(networkSumMultiEdges);
>
>
> How can I reduce and combine (1 2 20) and (2 1 10) to one Tuple?
>
>
> Best regards
> Marc
>
>
> Am 17.04.2017 um 21:47 schrieb Kaepke, Marc <[hidden email]>:
>
> Hi Gábor,
>
> thanks a lot
>
> Best,
> Marc
>
> Am 17.04.2017 um 20:32 schrieb Gábor Gévay <[hidden email]>:
>
> Hello Marc,
>
> You can group by edge, and then sum:
>
> edges
> .groupBy(0,1) // make first two fields a composite key
> .sum(2); // sum the value field
>
> This will turn multiple edges that have the same source and target
> into one edge, whose value will be the sum of the values of the
> original group of edges.
>
> Best,
> Gabor
>
> PS.: Sorry for the duplicate email, I accidentally sent my previous
> email only to you instead of the mailing list.
>
>
>
>
> On Mon, Apr 17, 2017 at 5:46 PM, Kaepke, Marc
> <[hidden email]> wrote:
>
> Hi,
>
> how can I sum and reduce multiple edges in my entire graph?
>
> e.g. my input graph looks like (source-ID, target-ID, value):
> (1, 2, 30)
> (1, 2, 10)
> (2, 1, 55)
>
> And I need:
> (1, 2, 40)
> (2, 1, 55)
>
>
> Thanks!
> Marc
>
>
>