I am trying to generate the powerset of a list of node elements in a graph. I have identified and adapted the following code from a previous post (Unique Combination of Set)
Public Function PowerSet(ByVal s As List(Of Node)) As List(Of List(Of Node))
Dim ini As List(Of List(Of Node)) = New List(Of List(Of Node))
Return s.Aggregate(ini, Function(a, b) a.Concat(a.Select(Function(x) x.Concat({b}))))
End Function
I am testing the function using
For Each x In G.PowerSet(G.internal_nodes_in_path)
Console.WriteLine(x)
Next
However, I get an invalid cast exception error pointing at function(a,b) in the PowerSet function:
Additional information: Unable to cast object of type 'WhereSelectListIterator2[System.Collections.Generic.List
1[cDAG_with_classes.Node],System.Collections.Generic.IEnumerable1[cDAG_with_classes.Node]]' to type 'System.Collections.Generic.IEnumerable
1[System.Collections.Generic.List`1[cDAG_with_classes.Node]]'.
Can anyone offer some advice on where I might be going wrong?
Thanks