Ho estrapolato il minimo indispensabile per riprodurre l'errore:
codice:
namespace Proof
{
public class ColoredGraph<V, E>
where V : IEquatable<V>
where E : IEquatable<E>
{
public class Vertex : IEquatable<Vertex>
{
public Int32 Index { get; internal set; }
public V Data { get; set; }
internal List<Edge> OutgoingEdgesList;
internal List<Edge> IncomingEdgesList;
public ReadOnlyCollection<Edge> OutgoingEdges { get; private set; }
public ReadOnlyCollection<Edge> IncomingEdges { get; private set; }
public IEnumerable<Vertex> Children
{
get
{
foreach (Edge edge in this.OutgoingEdges)
yield return edge.End;
}
}
internal Vertex()
{
this.OutgoingEdgesList = new List<Edge>();
this.IncomingEdgesList = new List<Edge>();
this.OutgoingEdges = new ReadOnlyCollection<Edge>(this.OutgoingEdgesList);
this.IncomingEdges = new ReadOnlyCollection<Edge>(this.IncomingEdgesList);
}
public override string ToString()
{
return '{' + this.Data.ToString() + ", " + this.Index + '}';
}
public bool Equals(Vertex other)
{
if (other == null)
return false;
return (this.Index == other.Index) && this.Data.Equals(other.Data);
}
}
public class Edge : IEquatable<Edge>
{
public Vertex Start { get; set; }
public Vertex End { get; set; }
public E Data { get; set; }
internal Edge() { }
public override string ToString()
{
return String.Format("{0} : {1} -> {2}", this.Data.ToString(), this.Start.ToString(), this.End.ToString());
}
public bool Equals(Edge other)
{
if (other == null)
return false;
return (this.Start == other.Start) && (this.End == other.End) && this.Data.Equals(other.Data);
}
public Boolean IsLoop()
{
return this.Start.Equals(this.End);
}
}
protected List<Vertex> vertices;
public ReadOnlyCollection<Vertex> Vertices { get; protected set; }
// ...
}
public class ColoredTree<V, E> : ColoredGraph<V, E>
where V : IEquatable<V>
where E : IEquatable<E>
{
protected Vertex root;
public Vertex Root
{
get { return root; }
set
{
if (value.IncomingEdges.Count > 0)
throw new ArgumentException("The root vertex should not have any incoming edges.");
root = value;
}
}
public ColoredTree() : base() { }
public Int32 GetHeight()
{
if (this.Root == null)
throw new InvalidOperationException("Cannot calculate the height of an unrooted tree.");
return this.GetHeight(this.Root);
}
private Int32 GetHeight(Vertex vertex)
{
if (vertex.OutgoingEdges.Count == 0)
return 0;
return 1 + vertex.OutgoingEdges.Select(edge => this.GetHeight(edge.End)).Max();
}
public Boolean IsIsomorphicTo<H, K>(ColoredTree<H, K> tree)
{
Int32 h = Math.Max(this.GetHeight(), tree.GetHeight());
}
private static Int32 GetRootLabel<H, K>(ColoredTree<H, K> tree)
{
List<Vertex>[] levels = new List<Vertex>[tree.GetHeight() + 1];
for (Int32 i = 0; i < levels.Length; i++)
levels[i] = new List<Vertex>();
levels[0].Add(tree.Root);
for (Int32 i = 1; i < levels.Length; i++)
levels[i].AddRange(levels[i - 1].SelectMany(vertex => vertex.Children));
var data = from vertex in tree.Vertices
select new { Vertex = vertex, Label = 0, OrderedLabels = new List<Int32>(), OrderedChildren = new List<Vertex>() };
}
}
}
Sto scrivendo un'implementazione dell'algoritmo standard per verificare se due alberi sono isomorfici. Mi sono bloccato nella dichiarazione di data, perché viene riportato l'errore sopracitato evidenziando la clausola select.
Ho già cercato tutti i possibili risultati su google. La maggior parte sono dovuti a un uso scorretto del selettore equals nella clausola join, quindi li ho scartati. I rimanenti risultati sono di scarsa rilevanza. Il primo è una descrizione generica dell'errore (da msdn). Il secondo e il quinto sono causati dal tentativo di restituire una funzione lambda. Il terzo viene da experts-exchange, che non è un sito molto affidabile. Il quarto è solo un esempio stupido. Il quinto punta a questa stessa discussione. I successivi sono risultati di scarsa rilevanza in quanto non riportano l'errore ma solo alcune parole chiave della ricerca. Non c'è assolutamente niente...