Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3879624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:44:53+00:00 2026-05-19T22:44:53+00:00

First I’ll explain, then I’ll paste the code. I actually copied the code from

  • 0

First I’ll explain, then I’ll paste the code. I actually copied the code from this example
http://www.boost.org/doc/libs/1_45_0/libs/graph/example/prim-example.cpp
And then I’m trying to get it to work with an input from a text file, just like I did for the Boost Kruskal algorithm.

Using the debugger, I know that the second argument of this function wants the “end” the array of edges. That’s what I’m giving it with my function call, i don’t understand.

Graph g(edges, edge_array + num_edges, weights, num_nodes);

I get this error

1>c:\users\edmond\documents\visual studio 2008\projects\boost prim algo\boost prim algo\main.cpp(61) : error C2661: 'boost::adjacency_list<OutEdgeListS,VertexListS,DirectedS,VertexProperty,EdgeProperty>::adjacency_list' : no overloaded function takes 4 arguments
1>        with
1>        [
1>            OutEdgeListS=boost::vecS,
1>            VertexListS=boost::vecS,
1>            DirectedS=boost::undirectedS,
1>            VertexProperty=boost::property<boost::vertex_distance_t,int>,
1>            EdgeProperty=boost::property<boost::edge_weight_t,int>
1>        ]

Here is the full code. I have commented the original code, but you can also find the original code on the website I gave.

//=======================================================================
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, 
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#include <boost/config.hpp>
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/prim_minimum_spanning_tree.hpp>

int
main()
{
  using namespace boost;
  typedef adjacency_list < vecS, vecS, undirectedS,
    property<vertex_distance_t, int>, property < edge_weight_t, int > > Graph;
  typedef std::pair < int, int >E;

  //const int num_nodes = 5;
  //E edges[] = { E(0, 2), E(1, 3), E(1, 4), E(2, 1), E(2, 3),
  //  E(3, 4), E(4, 0)
  //};
  //int weights[] = { 1, 1, 2, 7, 3, 1, 1 };
  //int num_edges = 7;

//Lire un fichier contenant les 2 structures de données
int num_nodes = 0;
std::size_t num_edges = 0;
int * weights;
E * edge_array;
static char ligne[50];  //Ligne lue
bool premiereLignefaite = false;
FILE* fichier = fopen("graph_poids.txt", "r");
int i = 0;

while (fgets(ligne, 50, fichier) != NULL) //retourne 0 quand on a end-of-file
    {
        //La premiere ligne est différente
        if (premiereLignefaite == false) {
            //Initialiser une matrice d'adjacence NxN
            sscanf(ligne, "%d %d", &num_nodes, &num_edges );
            edge_array = new E[num_edges];
            weights = new int[num_edges];
            premiereLignefaite = true;
            continue;
        }
        //On construit notre liste d'arêtes
        int sommet1, sommet2, poids;
        sscanf(ligne, "%d %d %d", &sommet1, &sommet2, &poids);
        weights[i] = poids;
        edge_array[i].first = sommet1;
        edge_array[i].second = sommet2;
        i++;
    }

E* machin = edge_array + num_edges; //aller au dernier élément

  Graph g(edges, edge_array + num_edges, weights, num_nodes);
//Graph g(edges, edges + sizeof(edges) / sizeof(E), weights, num_nodes);
  property_map<Graph, edge_weight_t>::type weightmap = get(edge_weight, g);

  std::vector < graph_traits < Graph >::vertex_descriptor >
    p(num_vertices(g));

  prim_minimum_spanning_tree(g, &p[0]);

  for (std::size_t i = 0; i != p.size(); ++i)
    if (p[i] != i)
      std::cout << "parent[" << i << "] = " << p[i] << std::endl;
    else
      std::cout << "parent[" << i << "] = no parent" << std::endl;

  return EXIT_SUCCESS;
}

Here is some test data if you want to try it. The name of the file is graph_poids.txt

14 19 
0 2 4
0 4 9
0 1 7
1 6 2
2 3 6
3 5 7
3 4 4
4 13 9
5 7 7
5 6 6
6 8 9
6 10 4
7 9 4
7 8 7
8 11 7
8 10 7
9 12 7
9 11 10
12 13 5
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:44:53+00:00Added an answer on May 19, 2026 at 10:44 pm

    It should be “edge_array” and not “edges” (that one was part of the original code).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First I want to explain what am I doing and then my problem. I
First off, there's a bit of background to this issue available on my blog:
First let me say that I really feel directionless on this question. I am
first a little bit of documentation from the jQuery validation plugin: Use submitHandler to
First of all: this is not a homework assignment, it's for a hobby project
First, I created a xcode project and copied and pasted the CSS and javascript
First off, I know this may be a very stupid question, so don't shoot
First off, I created a screen cast, in order to explain what I have
First I try to explain the circumstances. I store the the filter expression in
First, let's get the security considerations out of the way. I'm using simple authentication

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.