Skip to content

Commit b25efa0

Browse files
committed
Add some extra options, this change was only half implemented
1 parent 324e84e commit b25efa0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

PGraph.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,16 @@
210210
%%%% GRAPH MAINTENANCE
211211
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212212

213-
214213
function v = add_node(g, coord, varargin)
215214
%PGraph.add_node Add a node
216215
%
217-
% V = G.add_node(X) adds a node/vertex with coordinate X (Dx1) and
216+
% V = G.add_node(X, OPTIONS) adds a node/vertex with coordinate X (Dx1) and
218217
% returns the integer node id V.
219218
%
220-
% V = G.add_node(X, VFROM) as above but connected by a directed edge from vertex VFROM with cost equal to the distance between the vertices.
221-
%
222-
% V = G.add_node(X, V2, C) as above but the added edge has cost C.
219+
% Options:
220+
% 'name',N Assign a string name N to this vertex
221+
% 'from',V Create a directed edge from vertex V with cost equal to the distance between the vertices.
222+
% 'cost',C If an edge is created use cost C
223223
%
224224
% Notes::
225225
% - Distance is computed according to the metric specified in the
@@ -233,6 +233,7 @@
233233

234234
opt.from = [];
235235
opt.name = [];
236+
opt.cost = NaN;
236237

237238
opt = tb_optparse(opt, varargin);
238239

@@ -248,7 +249,10 @@
248249

249250
% optionally add an edge
250251
if ~isempty(opt.from)
251-
g.add_edge(vfrom, v, opt.from);
252+
if isnan(opt.cost)
253+
opt.cost = g.distance(v, opt.from);
254+
end
255+
g.add_edge(opt.from, v, opt.cost);
252256
end
253257

254258
if ~isempty(opt.name)

0 commit comments

Comments
 (0)