# Minumum Spanning Tree in Lisp
![graph-title.png](graph-title.png?raw=true)
## Introduction
A problem that often appears in various guises is connecting
different "points" in an "equivalent" way, for example connecting them
with threads but without creating loops.
Another typical problem is to calculate the shortest route in a map
point to point.
There are several algorithms capable of solving these known problems
as the "Minimum Spanning Tree".
The purpose of this project is to implement **Prim's algorithm** for
the solution of the MST problem for non-directed and connected graphs
with non-negative weights.
To proceed with the implementation of these algorithms it is necessary
produce an implementation of a MINHEAP (or MIN-PRIORITY-QUEUE).
*(We couldn't use default library for heap data structure and had to produce
it ourselves)*
My solution to the problem strives to maximize memory and time efficiency
and at the same time fulfill API's assignment specifications.
By avoiding storing arcs in hash-tables with key *(graph-id v1 v2)* and as
value its *Weight* I tried to find a more efficient way to store data.
Arcs data in my program are stored in nested-hash-tables structures
to drastically improve efficiency in searching operations.
In addition to this it also avoids increasing execution times caused
by multiple graphs existing simultaneously.
The downside to this implementation is that a "double" representation for
arcs is inevitable.
Moreover a temporary hash-table is needed to avoid double-arc
output in functions graph-arcs and graph-print.
*graphs* hash-table is optional since all graphs are also stored in first
"layer" as entry-point keys for the nested hash-tables structure in *arcs*.
I kept it just in case it was needed for unit-tests for the uni project.
# Instructions
This program outputs a Minimum Spanning tree for a given graph.
### [ Creating and editing a graph ]
Before any operation can be done you need to have a graph to work on.
You can create a graph by adding arcs with function:
```CommonLisp
CL > (new-arc graph-name vertex1 vertex2 weight)
```
vertex1 and vertex2 must be atoms. Weight must be numeric.
If not existent vertices and graph will be created along with arc.
Weight is optional and will be 1 if not specified.
For more control over graphs creation you can use functions new_graph
and new_vertex.
As new_arc, new_vertex will create the graph if doesn't exists.
```
CL > (new-graph graph-name)
CL > (new-vertex graph-name vertex-name)
```
### [ Printing a graph ]
To debug a state of any graph you may print it:
```
CL > (graph-print graph-name)
```
### [ Calculating Mst ]
MST will be given as a list of arcs obtained by pre-order visiting the
MST with radix source (vertex-name) and sorted first by weight and then
by lexicographical order for nodes on same depth.
Source is the starting vertex of computation.
```
CL > (mst-prim graph-name source)
(mst-get graph-name source)
```
### [ Memory Management ]
When a graph is no more needed, you may delete it with function:
```
CL > (delete-graph graph-name)
```
This will delete delete everything related to the graph in memory.
### [ More info for a given mst ]
If you want more hierarchical informations on a MST arc-list you can get the not-flattened
arc list with mst-get-nested function.
It returns a pre-ordered list of nested arcs representing the MST.
```
CL > (mst-get-nested graph-name source)
```
## Credits
OA: https://github.com/PhantoNa
Originally made for an university project, feel free to use.
没有合适的资源?快使用搜索试试~ 我知道了~
Minimum-Spanning-Trees-LISP:Lisp中的最小生成树
共4个文件
png:1个
md:1个
lisp:1个
需积分: 9 1 下载量 122 浏览量
2021-03-13
03:05:41
上传
评论
收藏 133KB ZIP 举报
温馨提示
Lisp中的最小生成树 介绍 经常以各种形式出现的问题是以“等效”方式连接不同的“点”,例如,将它们与线程连接而没有创建循环。 另一个典型的问题是计算点对点地图中的最短路径。 有几种能够解决这些已知问题的算法,称为“最小生成树”。 该项目的目的是实现Prim算法,以解决权重为非负的无向图和连通图的MST问题。 要继续执行这些算法,必须生成MINHEAP(或MIN-PRIORITY-QUEUE)的实现。 (我们不能将默认库用于堆数据结构,而必须自己生成) 我对这个问题的解决方案力求最大程度地提高内存和时间效率,同时满足API的分配规范。 通过避免使用键(graph-id v1 v2)和作为其权重值的哈希表将弧存储在哈希表中,我试图找到一种更有效的数据存储方式。 我程序中的Arcs数据存储在嵌套哈希表结构中,以大大提高搜索操作的效率。 除此之外,它还避免了由于同时存在多个图形而导
资源推荐
资源详情
资源评论
收起资源包目录
Minimum-Spanning-Trees-LISP-main.zip (4个子文件)
Minimum-Spanning-Trees-LISP-main
graph-title.png 128KB
LICENSE 1KB
mst.lisp 24KB
README.md 4KB
共 4 条
- 1
资源评论
生物医药从业者
- 粉丝: 17
- 资源: 4616
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功