提交 238ccdf0 创建 作者: 宋海霞's avatar 宋海霞

template

上级
流水线 #493 已失败 于阶段
/Debug
/Release
*.bak
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_cpp:latest"
stages:
- make
- case1
- teacher-check
variables:
TEMPLATE_REPO: "engintime/ds-lab/Project-Template/Lab020.git"
.codecode-runner: &codecode-runner
tags:
- ubuntu-16.04
- short-job
make:
stage: make
<<: *codecode-runner
script:
- make
- execscore.sh 40
only:
- master
case1:
stage: case1
<<: *codecode-runner
script:
- make
- ./app > user_output.txt
- diff output.txt user_output.txt -b -B -y -i --suppress-common-lines
- execscore.sh 100
only:
- master
teacher-check:
stage: teacher-check
<<: *codecode-runner
script:
- make
- ./app
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEMPLATE_REPO} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/output.txt output.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
only:
- master
when: manual
allow_failure: false
<?xml version="1.0" encoding="gb2312"?>
<OSLProject Version="1.00" Name="ShortestPath" SubjectID="cf4dda31-1275-49ef-9b0f-36a6eff372e4" ProjectTemplateID="9e586ee2-86f8-46e7-8689-b0e62abb320b" ProjectID="2e769659-9972-4b63-975c-93b106d67520" IsSubmitWork="0">
<Configurations>
<Configuration Name="Debug">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" AdditionalDependencies="&quot;$(DSLInstallDir)Dump\lib\ShortestPath_Floyd_Demo.o&quot;"/>
<Tool Name="PostBuildEventTool"/>
<VisualContext>
<WatchPoints>
<WatchPoint FunctionName="Floyd" ObserverID="DB1257E3-9233-46d2-B5A2-17D9AA0C253C">
</WatchPoint>
</WatchPoints>
</VisualContext>
</Configuration>
<Configuration Name="Release">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="PostBuildEventTool"/>
</Configuration>
</Configurations>
<Files>
<Filter Name="ͷļ" Filter="h;hpp;hxx">
<File RelativePath=".\ShortestPath.h">
</File>
</Filter>
<Filter Name="Դļ" Filter="cpp;c;cc;cxx">
<File RelativePath=".\main.c">
</File>
</Filter>
<File RelativePath=".\makefile">
</File>
<File RelativePath=".\output.txt">
</File>
<File RelativePath=".\readme.md">
</File>
</Files>
</OSLProject>
#ifndef _SHORTESTPATH_H_
#define _SHORTESTPATH_H_
//
// 在此处包含 C 标准库头文件
//
#include <stdio.h>
//
// 在此处包含其他头文件
//
//
// 在此处定义数据结构
//
#define MAX 100000000 // 表示两顶点间无边直接连接,邻接矩阵中用MAX表示
#define VERTEXNUM 6 // 顶点数量
typedef struct GraphMatrix{
int Arcs[VERTEXNUM][VERTEXNUM]; // 边信息
}GraphMatrix;
typedef struct ShortPath{
int a[VERTEXNUM][VERTEXNUM]; // 存放每对顶点间最短路径长度
int nextvex[VERTEXNUM][VERTEXNUM]; // 存放 Vi 到 Vj 最短路径上 Vi 的后继顶点的下标值
}ShortPath;
//
// 在此声明函数
//
void Floyd(GraphMatrix* pGraph, ShortPath* pPath);
void OutputResult(ShortPath* pPath);
//
// 在此处声明全局变量
//
extern ShortPath SPath;
#endif /* _SHORTESTPATH_H_ */
#include "ShortestPath.h"
ShortPath SPath;
int main(int argc, char* argv[])
{
//
// 初始化图(图的邻接矩阵表示法)
//
GraphMatrix Graph = {{
{ 0, 50, 10, MAX, 45, MAX},
{ MAX, 0, 15, MAX, 5, MAX},
{ 20, MAX, 0, 15, MAX, MAX},
{ MAX, 20, MAX, 0, 35, MAX},
{ MAX, MAX, MAX, 30, 0, MAX},
{ MAX, MAX, MAX, 3, MAX, 0}
}};
//
// 最短路径(佛洛伊德算法)
//
Floyd(&Graph, &SPath);
//
// 输出结果
//
OutputResult(&SPath);
return 0;
}
/*
功能:
最短路径的佛洛伊德算法
参数:
pPath -- 结构体指针
pGraph -- 图指针
*/
void Floyd(GraphMatrix* pGraph, ShortPath* pPath)
{
int i, j, k; // 游标
//
// TODO: 在此添加代码
//
}
/*
功能:
输出结果
参数:
*/
void OutputResult(ShortPath* pPath)
{
int i, j;
printf("Subsequent vertex index array:\n");
for(i = 0; i < VERTEXNUM; i++)
{
for(j = 0; j < VERTEXNUM; j++)
{
printf("%d ", pPath->nextvex[i][j]);
}
printf("\n");
}
printf("An array of shortest path lengths between vertices:\n");
for(i = 0; i < VERTEXNUM; i++)
{
for(j = 0; j < VERTEXNUM; j++)
{
if(pPath->a[i][j] == MAX)
{
printf("MAX ");
}
else
{
printf("%d ", pPath->a[i][j]);
}
}
printf("\n");
}
}
app:main.o
gcc -o app main.o
main.o:main.c ShortestPath.h
gcc -c -w -O3 -std=c99 -fsigned-char main.c -o main.o
Subsequent vertex index array:
0 2 2 2 4 -1
2 1 2 2 4 -1
0 3 2 3 3 -1
1 1 1 3 1 -1
3 3 3 3 4 -1
3 3 3 3 3 5
An array of shortest path lengths between vertices:
0 45 10 25 45 MAX
35 0 15 30 5 MAX
20 35 0 15 40 MAX
55 20 35 0 25 MAX
85 50 65 30 0 MAX
58 23 38 3 28 0
# 阅读实验源代码
**main.c文件**
在 main 函数中首先初始化了图,然后调用Floyd函数查找图中最短路径。
在main函数的后面,定义了图的最短路径查找函数Floyd,该函数的函数体还不完整,留给读者完成。
**ShortestPath.h文件**
定义了与图相关的数据结构并声明了相关的操作函数和全局变量。
# 在演示模式下调试项目
**按照下面的步骤调试项目:**
1. 按F7生成项目。
2. 在演示模式下,按F5启动调试项目。程序会在观察点函数的开始位置中断。
3. 重复按F5,直到调试过程结束。
在调试的过程中,每执行“演示流程”窗口中的一行后,仔细观察“可视化数据”窗口内容所发生的变化,理解查找最短路径函数的执行过程。“可视化数据”窗口显示的数据信息(如下图所示),包括:
- 游标 k。用来显示迭代计算最短路径的过程。
- 图的邻接矩阵。矩阵中的值表示顶点之间的距离。
- 存放每对顶点间最短路径长度的二维数组,以及Vi到Vj最短路径上Vi的后继顶点下标值的二维数组,如果对应的当前值与上一次不相同,用红色的字体显示。
- 在图中,分别显示了从某一个顶点(该顶点的边框是红色的双圆环)到各个顶点之间的最短路径,这些顶点之间用红色的边连接;未加入顶点的填充色为灰色,已加入顶点的填充色为白色。
![](./img/20_1.png)
![](./img/20_2.png)
# 编写源代码并通过验证
**按照下面的步骤继续实验:**
1. 为Floyd函数编写源代码。注意,尽量使用已定义的局部变量。
2. 按F7生成项目。如果生成失败,根据“输出”窗口中的提示信息修改源代码中的语法错误。
3. 按Alt+F5启动验证。如果验证失败,可以使用“输出”窗口中的“比较”功能,或者在“非演示模式”下按F5启动调试后重复按F10单步调试读者编写的源代码,从而定位错误的位置,然后回到步骤1。
# 教师参考答案
访问教师参考答案[domain relative url](engintime/ds-lab/teachers-packet/Lab020.git)
\ No newline at end of file
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论