File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 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
233233
234234 opt.from = [];
235235 opt.name = [];
236+ opt.cost = NaN ;
236237
237238 opt = tb_optparse(opt , varargin );
238239
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 )
You can’t perform that action at this time.
0 commit comments