10 Reputation

One Badge

5 years, 217 days

MaplePrimes Activity

These are questions asked by bvdmrsch

Hey there,


I'm trying to build a procedure that can function as an adapted form of Prim's algorithm. The idea is that on a graph with just vertices, the procedure has a starting point, and from there will find out which vertex is the cheapest to connect to (currently expressed purely by the lowest distance). Once this is found, the connected vertex is removed from a list that has vertices that aren't connected yet, and added to a list of vertices that are in the minimal spanning tree.

My problem is that I get an error returned that says "invalid Boolean expression", and I'm not sure how to solve it. Can anybody here point me in the right direction?

The procedure is defined as follows:

Primmetje := proc (aantal, posities, begin)
local knopenover, knopeninmst, huidig, V, kaart, e, a;
knopenover := [seq(i, i = 1 .. aantal)];
knopeninmst := {};
huidig := [0, 0];
if begin <> {} then
  V := [begin];
knopeninmst := knopeninmst union {V}
end if;
remove(V, knopenover);
kaart := Graph(aantal);
SetVertexPositions(kaart, posities);
while nops(knopeninmst) < aantal
do for e in knopeninmst
   do for a in knopenover
     do if huidig = [0, 0] or Distance(posities[e], posities[a]) < Distance(posities[huidig[1]], posities[huidig[2]]) then
   huidig := [e, a];
knopeninmst := knopeninmst union {a};
remove(a, knopenover);
AddEdge(kaart, huidig)
end if
end do
end do
end do
end proc

When I try to execute it with some parameters the return is this:

vp := [2.5, 21], [6, 13.5], [8, 10], [11, 24.5], [14.3, 19.4], [16.8, 26], [22, 21.5], [22, 17], [22.2, 12.5], [26.8, 23], [28, 20.5], [30, 25.5], [32, 21], [29.5, 16];
Primmetje(14, vp, 1);
Error, (in Primmetje) invalid boolean expression: [[6, 13.5]]

I think it has something to do with the double brackes, but I'm not sure how to solve it.

Page 1 of 1