The type arguments for method ToAdjacencyGraph error

Aug 27, 2009 at 4:30 PM

Hello, I am trying to create my first graph with QuickGraph using the following example code:

http://quickgraph.codeplex.com/Wiki/View.aspx?title=Creating%20Graphs&referringTitle=Home

Here is the code-behind for an C# 3.5 windows form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuickGraph;
using QuickGraph.Algorithms;

namespace TestQuickGraph
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var edges = new Edge<int>[] { new Edge<int>(1, 2), new Edge<int>(0, 1) };
            var graph = edges.ToAdjacencyGraph(edges); //error is here
        }

    }
}

 

I cannot get past this point, I receive an error:

Error    1    The type arguments for method 'QuickGraph.GraphExtensions.ToAdjacencyGraph<TVertex,TEdge>(System.Collections.Generic.IEnumerable<TVertex>, System.Func<TVertex,System.Collections.Generic.IEnumerable<TEdge>>)'

cannot be inferred from the usage. Try specifying the type arguments explicitly.

 

Can anyone help me resolve this error? It must be something simple I am doing wrong...

 

Thanks Before Hand,
Adiel

 

Coordinator
Aug 27, 2009 at 6:01 PM

Looks like C# does not infer the generic type arguments. I've updated the docs, try

 

            var edges = new SEdge<int>[] { new SEdge<int>(1,2), new SEdge<int>(0,1) };
            var graph = edges.ToAdjacencyGraph<int, SEdge<int>>();

Aug 28, 2009 at 1:13 PM

Thanks that worked great! :)  By the way I think you added an extra field in the doc update:

... SEdge<int>>(edges);

My next question if you dont mind, now that I have this graph, what is the easiest way to add vertices, edges and then have the graph display on a windows form.  If you have a sample code, I would gladly appreciate it.

 

Thanks Again,
Adiel

 

Coordinator
Aug 28, 2009 at 3:52 PM

AdjacencyGraph has methods like 'AddVertex', 'AddEdge', 'AddVertexRange', 'AddEdgeRange', etc... QuickGraph does not provide any graph viewer, other project provide such functionality (i.e. MsAgl or Graph#).

Aug 28, 2009 at 4:14 PM

Thanks, I seem to be having a problem finding Graph#.  Do you have their website?

Thanks,
Adiel

 

Aug 28, 2009 at 4:29 PM

hi look for graphSharp :) 

http://graphsharp.codeplex.com/

have a nice day