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

template

上级
流水线 #484 已失败 于阶段
/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/Lab019.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="aab2781b-a760-410d-9538-4694e3234fad" ProjectID="05fc695a-2a22-4dee-aa8d-0e5e79c60a86" 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_Dijkstra_Demo.o&quot;"/>
<Tool Name="PostBuildEventTool"/>
<VisualContext>
<WatchPoints>
<WatchPoint FunctionName="Dijkstra" ObserverID="70D8D512-DEF2-401d-BC80-51EC0A522B30">
</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 ShortestPath{
int length; // 最短路径长度
int prevex; // 从 Vo 到达 Vi 的最短路径上 Vi 的前驱顶点
}ShortestPath;
//
// 声明函数
//
void Dijkstra(GraphMatrix* pGraph);
void OutputResult(GraphMatrix* pGraph);
//
// 在此处声明全局变量
//
extern ShortestPath dist[MAX];
#endif /* _SHORTESTPATH_H_ */
#include "ShortestPath.h"
ShortestPath dist[MAX];
int main(int argc, char* argv[])
{
//
// 初始化图(图的邻接矩阵表示法)
//
GraphMatrix Graph = {{
{ 0, 50, 10, MAX, 45, MAX},
{ MAX, 0, 15, MAX, 5, MAX},
{ 20, 100, 0, 15, MAX, MAX},
{ MAX, 20, MAX, 0, 35, MAX},
{ MAX, MAX, MAX, 30, 0, MAX},
{ MAX, MAX, MAX, 3, MAX, 0}
}};
//
// 最短路径(迪杰斯特拉算法)
//
Dijkstra(&Graph);
//
// 输出结果
//
OutputResult(&Graph);
return 0;
}
/*
功能:
最短路径的迪杰斯特拉算法
参数:
pGraph -- 图指针
*/
void Dijkstra(GraphMatrix* pGraph)
{
int i; // 游标
int mv, minw; // 存储最短路径中节点下标和长度
//
// TODO: 在此添加代码
//
}
/*
功能:
输出结果
参数:
*/
void OutputResult(GraphMatrix* pGraph)
{
int i;
printf("ShortestPath: ");
for(i=0; i < VERTEXNUM; i++)
{
if(pGraph->Arcs[i][i] == 1)
{
printf("[%3d, %2d]", dist[i].length, dist[i].prevex);
}
else
{
if(dist[i].length == MAX)
{
printf("(%3s, %2d)", "MAX", dist[i].prevex);
}
else
{
printf("(%3d, %2d)", dist[i].length, dist[i].prevex);
}
}
}
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
ShortestPath: [ 0, 0][ 45, 3][ 10, 0][ 25, 2][ 45, 0](MAX, -1)
# 阅读实验源代码
**main.c文件**
在 main 函数中首先初始化了图,然后调用Dijkstra函数查找图中最短路径。
在main函数的后面,定义了图的最短路径查找函数Dijkstra,该函数的函数体还不完整,留给读者完成。
**ShortestPath.h文件**
定义了与图相关的数据结构并声明了相关的操作函数和全局变量。
# 在演示模式下调试项目
**按照下面的步骤调试项目:**
1. 按F7生成项目。
2. 在演示模式下,按F5启动调试项目。程序会在观察点函数的开始位置中断。
3. 重复按F5,直到调试过程结束。
在调试的过程中,每执行“演示流程”窗口中的一行后,仔细观察“可视化数据”窗口内容所发生的变化,理解查找最短路径函数的执行过程。“可视化数据”窗口显示的数据信息(如下图所示),包括:
- 图的邻接矩阵。矩阵中的值表示顶点之间的距离。
- 在图中,未选出的顶点的填充色为灰色,已选出的顶点的填充色为白色;各个顶点之间的最短路径用红色的边进行连接。
- 在调试的过程中,可以看到游标的移动。
![最短路径(迪杰斯特拉算法)](./img/19.png)
# 编写源代码并通过验证
**按照下面的步骤继续实验:**
1. 为Dijkstra函数编写源代码。注意,尽量使用已定义的局部变量。
2. 按F7生成项目。如果生成失败,根据“输出”窗口中的提示信息修改源代码中的语法错误。
3. 按Alt+F5启动验证。如果验证失败,可以使用“输出”窗口中的“比较”功能,或者在“非演示模式”下按F5启动调试后重复按F10单步调试读者编写的源代码,从而定位错误的位置,然后回到步骤1。
# 教师参考答案
访问教师参考答案[domain relative url](engintime/ds-lab/teachers-packet/Lab019.git)
\ No newline at end of file
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论