Sha256: 02c4f7c5681443e9b8d5dbf5acc1521dca0004a56b5141107450d8a125e08a1a

Contents?: true

Size: 899 Bytes

Versions: 17

Compression:

Stored size: 899 Bytes

Contents

proc dijkstra {graph origin} {
    # Initialize
    dict for {vertex distmap} $graph {
	dict set dist $vertex Inf
	dict set path $vertex {}
    }
    dict set dist $origin 0
    dict set path $origin [list $origin]
 
    while {[dict size $graph]} {
	# Find unhandled node with least weight
	set d Inf
	dict for {uu -} $graph {
	    if {$d > [set dd [dict get $dist $uu]]} {
		set u $uu
		set d $dd
	    }
	}
 
	# No such node; graph must be disconnected
	if {$d == Inf} break
 
	# Update the weights for nodes\
	 lead to by the node we've picked
	dict for {v dd} [dict get $graph $u] {
	    if {[dict exists $graph $v]} {
		set alt [expr {$d + $dd}]
		if {$alt < [dict get $dist $v]} {
		    dict set dist $v $alt
		    dict set path $v [list {*}[dict get $path $u] $v]
		}
	    }
	}
 
	# Remove chosen node from graph still to be handled
	dict unset graph $u
    }
    return [list $dist $path]
}

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
agile-proxy-0.1.24 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.23 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.22 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.21 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.20 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.19 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.18 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.13 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.12 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.11 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.10 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.9 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.8 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.7 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.6 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.5 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl
agile-proxy-0.1.4 assets/ui/bower_components/ace-builds/demo/kitchen-sink/docs/tcl.tcl