Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,33 @@
data vertex <'a'..'f'>, to <vertex>
templates shortestPaths&{graph:}
@: [];
[ {to: $, distance: 0"1", path:[]} ] -> #
when <[](0)> do $@ !
otherwise
def closest: $ ... -> ..=Min&{by: :(distance:), select: :()};
$closest -> ..|@: $;
def path: [ $closest.path..., $closest.to ];
[ $... -> \(<?($.to <~=$closest.to>)> $!\),
$graph... -> \(<?($.edge(1) <=$closest.to>) ?($@shortestPaths <~[<{to: <=$.edge(2)>}>]>)> $!\)
-> { to: $.edge(2), distance: $.cost + $closest.distance, path: $path} ] -> #
end shortestPaths
def edges: [
{ edge: [vertex´'a', vertex´'b'], cost: 7"1" },
{ edge: [vertex´'a', vertex´'c'], cost: 9"1" },
{ edge: [vertex´'a', vertex´'f'], cost: 14"1" },
{ edge: [vertex´'b', vertex´'c'], cost: 10"1" },
{ edge: [vertex´'b', vertex´'d'], cost: 15"1" },
{ edge: [vertex´'c', vertex´'d'], cost: 11"1" },
{ edge: [vertex´'c', vertex´'f'], cost: 2"1" },
{ edge: [vertex´'d', vertex´'e'], cost: 6"1" },
{ edge: [vertex´'e', vertex´'f'], cost: 9"1" }];
def fromA: vertex´'a' -> shortestPaths&{graph: $edges};
$fromA... -> \(<{to:<=vertex´'e'>}> $!\) -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last);
' -> !OUT::write
$fromA... -> \(<{to:<=vertex´'f'>}> $!\) -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last);
' -> !OUT::write

View file

@ -0,0 +1,36 @@
data cost <"1">, distance <"1">
data vertex <'[a-f]'>, to <vertex>, from <vertex>, path <[<vertex>* VOID]>
templates shortestPaths&{graph:}
@: {||};
{| {to: $, distance: 0"1", path:[]} |} -> #
when <?($::count <=0>)> do $@ !
otherwise
def closest: $ ... -> ..=Min&{by: :(distance:), select: :()};
@: ($@ union {|$closest|});
def path: [ $closest.path..., $closest.to ];
{| ($ notMatching {| $closest({to:}) |})...,
(($graph matching {| $closest({from: §.to}) |}) notMatching $@({to:}))...
-> { to: $.to, distance: $.cost + $closest.distance, path: $path}
|} -> #
end shortestPaths
def edges: {|
{ from: vertex´'a', to: vertex´'b', cost: 7"1" },
{ from: vertex´'a', to: vertex´'c', cost: 9"1" },
{ from: vertex´'a', to: vertex´'f', cost: 14"1" },
{ from: vertex´'b', to: vertex´'c', cost: 10"1" },
{ from: vertex´'b', to: vertex´'d', cost: 15"1" },
{ from: vertex´'c', to: vertex´'d', cost: 11"1" },
{ from: vertex´'c', to: vertex´'f', cost: 2"1" },
{ from: vertex´'d', to: vertex´'e', cost: 6"1" },
{ from: vertex´'e', to: vertex´'f', cost: 9"1" }
|};
def fromA: vertex´'a' -> shortestPaths&{graph: $edges};
($fromA matching {|{to:vertex´'e'}|})... -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last);
' -> !OUT::write
($fromA matching {|{to:vertex´'f'}|})... -> 'Shortest path from $.path(1); to $.to; is distance $.distance; via $.path(2..last);
' -> !OUT::write