| <<O>> Difference Topic GraphParametricTypeExample (r1.8 - 22 Apr 2005 - TWikiGuest) |
| <<O>> Difference Topic GraphParametricTypeExample (r1.7 - 31 Jan 2005 - LiYan) |
| <<O>> Difference Topic GraphParametricTypeExample (r1.6 - 25 Jan 2005 - LiYan) |
| Added: | |
| > > | 展示架 生物反应器 笔记本电脑 成人用品 翻译 鲜花 移民 翻译公司 租房 游戏 游戏下载 摸屏 壁纸 服务器 爱滋病 办公自动化 出国 短信 干燥设备 交友 聊天 门禁 内衣 升降机 视频 写真 仪器仪表 移动存储 音乐 自考 算命 惠普 诺基亚 体育彩票 网页制作 前列腺 索尼 宠物 大连 电力 福利彩票 个人主页 广告公司 国际贸易 会计 计算机等级考试 交通 宽带 免费空间 农业 企业文化 人才 人才网 设计 手机报价 图书 网络 网络游戏 物业管理 西门子 小灵通 幼儿教育 幼儿园 娱乐 注册会计师 财务 财务管理 出国留学 电脑培训 多媒体 翻译软件 飞机票 购物 管理 婚纱摄影 激光 计算机培训 空间 律师 律师事务所 贸易 美容美发 模型 纳米 商标 数据库 通讯 网络安全 项目管理 鞋 雅思 英语培训 园林 招标 纸 中医 |
| <<O>> Difference Topic GraphParametricTypeExample (r1.5 - 13 Jan 2005 - DanielBonniot) |
| <<O>> Difference Topic GraphParametricTypeExample (r1.4 - 07 Feb 2004 - IsaacGouy) |
| Changed: | |
| < < | The generic algorithms BreadthFirstSearchExample, DijkstraShortestPathsExample, PrimMinimumSpanningTreeExample, BellmanFordShortestPathsExample, and JohnsonAllPairsShortestPathsExample, make use of GraphConceptsExample and GraphClassesExample and GraphTestExample. |
| > > | The generic algorithms Breadth First Search, Dijkstra Shortest Paths, Prim's Minimum Spanning Tree, Bellman Ford Shortest Paths, and Johnson All Pairs Shortest Paths, make use of Graph Concepts and Graph Classes and Graph Tests. |
| Changed: | |
| < < | (For tests in GraphTestExample.) |
| > > | (See test code) |
| Added: | |
| > > | %META:TOPICMOVED{by="IsaacGouy" date="1076170967" from="Doc.GenericProgrammingIntermediateExample" to="Doc.GraphParametricTypeExample"}% |
| <<O>> Difference Topic GraphParametricTypeExample (r1.3 - 20 Jan 2004 - IsaacGouy) |
| Changed: | |
| < < | for (i : 40003..40006) { |
| > > | for (i : 3..6) { |
| Changed: | |
| < < | // Maybe a Vertex has no predecessors? 40003 |
| > > | // Maybe a Vertex has no predecessors? 3 |
| Changed: | |
| < < | initialize 40003 initialize 40004 initialize 40005 initialize 40006 discover 40003 discover 40003 examine edge(40003 -> 40006) tree edge(40003 -> 40006) examine edge(40003 -> 40005) tree edge(40003 -> 40005) finish 40003 discover 40006 examine edge(40006 -> 40004) tree edge(40006 -> 40004) finish 40006 discover 40005 finish 40005 discover 40004 examine edge(40004 -> 40005) nontree edge(40004 -> 40005) black target edge(40004 -> 40005) examine edge(40004 -> 40003) nontree edge(40004 -> 40003) black target edge(40004 -> 40003) finish 40004 |
| > > | initialize 3 initialize 4 initialize 5 initialize 6 discover 3 discover 3 examine edge(3 -> 6) tree edge(3 -> 6) examine edge(3 -> 5) tree edge(3 -> 5) finish 3 discover 6 examine edge(6 -> 4) tree edge(6 -> 4) finish 6 discover 5 finish 5 discover 4 examine edge(4 -> 5) nontree edge(4 -> 5) black target edge(4 -> 5) examine edge(4 -> 3) nontree edge(4 -> 3) black target edge(4 -> 3) finish 4 |
| Changed: | |
| < < | Dist(40003)=0.0, Pred(40003)=40003 Dist(40004)=7.0, Pred(40004)=40006 Dist(40005)=8.0, Pred(40005)=40003 Dist(40006)=5.0, Pred(40006)=40003 |
| > > | Dist(3)=0.0, Pred(3)=3 Dist(4)=7.0, Pred(4)=6 Dist(5)=8.0, Pred(5)=3 Dist(6)=5.0, Pred(6)=3 |
| Changed: | |
| < < | Pred(40003) = 40003 Pred(40004) = 40006 Pred(40005) = 40004 Pred(40006) = 40003 |
| > > | Pred(3) = 3 Pred(4) = 6 Pred(5) = 4 Pred(6) = 3 |
| Changed: | |
| < < | Dist(40003)=0.0, Pred(40003)= Dist(40004)=3.0, Pred(40004)=40006 Dist(40005)=2.0, Pred(40005)=40004 Dist(40006)=5.0, Pred(40006)=40003 |
| > > | Dist(3)=0.0, Pred(3)= Dist(4)=3.0, Pred(4)=6 Dist(5)=2.0, Pred(5)=4 Dist(6)=5.0, Pred(6)=3 |
| Changed: | |
| < < | 40003: 0.0 3.0 2.0 5.0 40004: 3.0 0.0 -1.0 8.0 40005: Infinity Infinity 0.0 Infinity 40006: 1.0 -2.0 -3.0 0.0 |
| > > | 3: 0.0 3.0 2.0 5.0 4: 3.0 0.0 -1.0 8.0 5: Infinity Infinity 0.0 Infinity 6: 1.0 -2.0 -3.0 0.0 |
| <<O>> Difference Topic GraphParametricTypeExample (r1.2 - 08 Jan 2004 - IsaacGouy) |
| Changed: | |
| < < | The generic algorithms BreadthFirstSearchExample, DijkstraShortestPathsExample, PrimMinimumSpanningTreeExample, BellmanFordShortestPathsExample, and JohnsonAllPairsShortestPathsExample, make use of GraphConceptsExamples and GraphClassesExamples. |
| > > | The generic algorithms BreadthFirstSearchExample, DijkstraShortestPathsExample, PrimMinimumSpanningTreeExample, BellmanFordShortestPathsExample, and JohnsonAllPairsShortestPathsExample, make use of GraphConceptsExample and GraphClassesExample and GraphTestExample. |
| <<O>> Difference Topic GraphParametricTypeExample (r1.1 - 07 Jan 2004 - IsaacGouy) |
| Added: | |
| > > |
%META:TOPICINFO{author="IsaacGouy" date="1073512440" format="1.0" version="1.1"}%
%META:TOPICPARENT{name="CodeExamples"}%
"A Comparative Study of Language Support for Generic Programming" used a sample of the Boost Graph Library to compare the generic programming techniques available in C++, ML, Haskell, Eiffel, Java Generics, Generic C# (Source code). These Nice implementations use parameterised interfaces to represent most concepts (a few are represented by functions).
The generic algorithms BreadthFirstSearchExample, DijkstraShortestPathsExample, PrimMinimumSpanningTreeExample, BellmanFordShortestPathsExample, and JohnsonAllPairsShortestPathsExample, make use of GraphConceptsExamples and GraphClassesExamples.
Bellman Ford Shortest Paths
package graph;
<Vertex, Edge, Distance, T | Edge <: GraphEdge<Vertex> >
boolean bellmanFordShortestPaths(
EdgeListGraph<Vertex,Edge> graph,
int size,
ReadablePropertyMap<Edge,Distance> weightMap,
ReadWritePropertyMap<Vertex,Vertex> predecessor,
ReadWritePropertyMap<Vertex,Distance> distance,
(Distance, Distance)->Distance combine,
(Distance, Distance)->boolean compare
){
for (int i = 0; i < size; ++i) {
boolean anyRelaxed = false; // Optimization from BGL
for ( Edge edge : graph.edges )
if( relax(edge, weightMap, distance, predecessor, combine, compare) )
anyRelaxed = true;
if (!anyRelaxed) break;
}
for ( Edge edge : graph.edges() )
if (compare(
combine(weightMap[edge], distance[edge.source]),
distance[edge.target])
)
return false;
return true;
}
void bellmanFordTest(){
AdjacencyList <int, AdjacencyListEdge<int>> g = simpleGraph();
HashPropertyMap<int, double> distanceMap = simpleDistanceMap();
HashPropertyMap<AdjacencyListEdge<int>, double> weightMap = negativeWeights();
HashPropertyMap<int, int> predMap = new HashPropertyMap();
bellmanFordShortestPaths(
g,
4,
weightMap,
predMap,
distanceMap,
(double a, double b) => { return a + b; },
(double a, double b) => { return a < b; }
);
for (i : 40003..40006) {
print("Dist(" i ")=" distanceMap.get(i));
print(", Pred(" i ")=");
// Maybe a Vertex has no predecessors? 40003
try { print( predMap.get(i) );
} catch (NoSuchElementException ex){}
println("");
}
}
Test Results(For tests in GraphTestExample.)Breadth First Search Test ========================= initialize 40003 initialize 40004 initialize 40005 initialize 40006 discover 40003 discover 40003 examine edge(40003 -> 40006) tree edge(40003 -> 40006) examine edge(40003 -> 40005) tree edge(40003 -> 40005) finish 40003 discover 40006 examine edge(40006 -> 40004) tree edge(40006 -> 40004) finish 40006 discover 40005 finish 40005 discover 40004 examine edge(40004 -> 40005) nontree edge(40004 -> 40005) black target edge(40004 -> 40005) examine edge(40004 -> 40003) nontree edge(40004 -> 40003) black target edge(40004 -> 40003) finish 40004 Dijkstra Shortest Paths Test ============================ Dist(40003)=0.0, Pred(40003)=40003 Dist(40004)=7.0, Pred(40004)=40006 Dist(40005)=8.0, Pred(40005)=40003 Dist(40006)=5.0, Pred(40006)=40003 Prim Minimum Spanning Tree Test =============================== Pred(40003) = 40003 Pred(40004) = 40006 Pred(40005) = 40004 Pred(40006) = 40003 Bellman-Ford Shortest Paths Test ================================ Dist(40003)=0.0, Pred(40003)= Dist(40004)=3.0, Pred(40004)=40006 Dist(40005)=2.0, Pred(40005)=40004 Dist(40006)=5.0, Pred(40006)=40003 Johnson All-Pairs Shortest Paths Test ===================================== 40003: 0.0 3.0 2.0 5.0 40004: 3.0 0.0 -1.0 8.0 40005: Infinity Infinity 0.0 Infinity 40006: 1.0 -2.0 -3.0 0.0-- IsaacGouy - 07 Jan 2004 |
| Topic GraphParametricTypeExample . { View | Diffs | r1.8 | > | r1.7 | > | r1.6 | More } |
|
Revision r1.1 - 07 Jan 2004 - 21:54 GMT - IsaacGouy Revision r1.8 - 22 Apr 2005 - 10:52 GMT - TWikiGuest |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |