Skip to content

Commit 75198a0

Browse files
committed
PBL1
0 parents  commit 75198a0

28 files changed

+1082
-0
lines changed

AllMethod.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef allmethod
2+
#define allmethod
3+
#include <stdio.h>
4+
#include "constant.h"
5+
6+
void Dijkstra(double *ShD, int trace[], pGraph graph, int S, int F);
7+
8+
//int Ford_Bellman(double d[], int trace[], pGraph graph, int S);
9+
10+
int Ford_Bellman2(double d[], int trace[], pGraph graph, int S);
11+
12+
int initMat(FILE *f);
13+
14+
int EnterMatrix(FILE *f);
15+
16+
pGraph MatrixToList(FILE *f, int *sign);
17+
18+
int checkinput1(char *s);
19+
#endif
20+
21+
646 KB
Binary file not shown.
Binary file not shown.

Makefile.win

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Project: PBL1
2+
# Makefile created by Dev-C++ 5.11
3+
4+
CPP = g++.exe
5+
CC = gcc.exe
6+
WINDRES = windres.exe
7+
OBJ = main.o dijkstra.o adjacency_list.o randomMatrix.o readFromKeyboard.o ford_bellman.o
8+
LINKOBJ = main.o dijkstra.o adjacency_list.o randomMatrix.o readFromKeyboard.o ford_bellman.o
9+
LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib" -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc
10+
INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include"
11+
CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++"
12+
BIN = PBL1.exe
13+
CXXFLAGS = $(CXXINCS) -std=c++11
14+
CFLAGS = $(INCS) -std=c++11
15+
RM = rm.exe -f
16+
17+
.PHONY: all all-before all-after clean clean-custom
18+
19+
all: all-before $(BIN) all-after
20+
21+
clean: clean-custom
22+
${RM} $(OBJ) $(BIN)
23+
24+
$(BIN): $(OBJ)
25+
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
26+
27+
main.o: main.cpp
28+
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)
29+
30+
dijkstra.o: dijkstra.cpp
31+
$(CPP) -c dijkstra.cpp -o dijkstra.o $(CXXFLAGS)
32+
33+
adjacency_list.o: adjacency_list.cpp
34+
$(CPP) -c adjacency_list.cpp -o adjacency_list.o $(CXXFLAGS)
35+
36+
randomMatrix.o: randomMatrix.cpp
37+
$(CPP) -c randomMatrix.cpp -o randomMatrix.o $(CXXFLAGS)
38+
39+
readFromKeyboard.o: readFromKeyboard.cpp
40+
$(CPP) -c readFromKeyboard.cpp -o readFromKeyboard.o $(CXXFLAGS)
41+
42+
ford_bellman.o: ford_bellman.cpp
43+
$(CPP) -c ford_bellman.cpp -o ford_bellman.o $(CXXFLAGS)

PBL1.dev

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
[Project]
2+
FileName=PBL1.dev
3+
Name=PBL1
4+
Type=1
5+
Ver=2
6+
ObjFiles=
7+
Includes=
8+
Libs=
9+
PrivateResource=
10+
ResourceIncludes=
11+
MakeIncludes=
12+
Compiler=
13+
CppCompiler=
14+
Linker=
15+
IsCpp=1
16+
Icon=
17+
ExeOutput=
18+
ObjectOutput=
19+
LogOutput=
20+
LogOutputEnabled=0
21+
OverrideOutput=0
22+
OverrideOutputName=
23+
HostApplication=
24+
UseCustomMakefile=0
25+
CustomMakefile=
26+
CommandLine=
27+
Folders=
28+
IncludeVersionInfo=0
29+
SupportXPThemes=0
30+
CompilerSet=0
31+
CompilerSettings=0000000000000000000000000
32+
UnitCount=8
33+
34+
[VersionInfo]
35+
Major=1
36+
Minor=0
37+
Release=0
38+
Build=0
39+
LanguageID=1033
40+
CharsetID=1252
41+
CompanyName=
42+
FileVersion=
43+
FileDescription=Developed using the Dev-C++ IDE
44+
InternalName=
45+
LegalCopyright=
46+
LegalTrademarks=
47+
OriginalFilename=
48+
ProductName=
49+
ProductVersion=
50+
AutoIncBuildNr=0
51+
SyncProduct=1
52+
53+
[Unit1]
54+
FileName=main.cpp
55+
CompileCpp=1
56+
Folder=
57+
Compile=1
58+
Link=1
59+
Priority=1000
60+
OverrideBuildCmd=0
61+
BuildCmd=
62+
63+
[Unit2]
64+
FileName=AllMethod.h
65+
CompileCpp=1
66+
Folder=
67+
Compile=1
68+
Link=1
69+
Priority=1000
70+
OverrideBuildCmd=0
71+
BuildCmd=
72+
73+
[Unit3]
74+
FileName=dijkstra.cpp
75+
CompileCpp=1
76+
Folder=
77+
Compile=1
78+
Link=1
79+
Priority=1000
80+
OverrideBuildCmd=0
81+
BuildCmd=
82+
83+
[Unit4]
84+
FileName=adjacency_list.cpp
85+
CompileCpp=1
86+
Folder=
87+
Compile=1
88+
Link=1
89+
Priority=1000
90+
OverrideBuildCmd=0
91+
BuildCmd=
92+
93+
[Unit6]
94+
FileName=constant.h
95+
CompileCpp=1
96+
Folder=
97+
Compile=1
98+
Link=1
99+
Priority=1000
100+
OverrideBuildCmd=0
101+
BuildCmd=
102+
103+
[Unit5]
104+
FileName=randomMatrix.cpp
105+
CompileCpp=1
106+
Folder=
107+
Compile=1
108+
Link=1
109+
Priority=1000
110+
OverrideBuildCmd=0
111+
BuildCmd=
112+
113+
[Unit7]
114+
FileName=readFromKeyboard.cpp
115+
CompileCpp=1
116+
Folder=
117+
Compile=1
118+
Link=1
119+
Priority=1000
120+
OverrideBuildCmd=0
121+
BuildCmd=
122+
123+
[Unit9]
124+
FileName=ford_bellman.cpp
125+
Folder=
126+
Compile=1
127+
Link=1
128+
Priority=1000
129+
OverrideBuildCmd=0
130+
BuildCmd=
131+
CompileCpp=1
132+
133+
[Unit8]
134+
FileName=ford_bellman.cpp
135+
CompileCpp=1
136+
Folder=
137+
Compile=1
138+
Link=1
139+
Priority=1000
140+
OverrideBuildCmd=0
141+
BuildCmd=
142+

PBL1.exe

147 KB
Binary file not shown.

PBL1.layout

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[Editors]
2+
Order=0,5,1,4,6,3,2,7
3+
Focused=3
4+
[Editor_0]
5+
CursorCol=19
6+
CursorRow=73
7+
TopLine=297
8+
LeftChar=1
9+
[Editor_1]
10+
CursorCol=30
11+
CursorRow=16
12+
TopLine=1
13+
LeftChar=1
14+
[Editor_2]
15+
CursorCol=2
16+
CursorRow=25
17+
TopLine=16
18+
LeftChar=1
19+
[Editor_3]
20+
CursorCol=19
21+
CursorRow=88
22+
TopLine=71
23+
LeftChar=1
24+
[Editor_4]
25+
CursorCol=12
26+
CursorRow=21
27+
TopLine=1
28+
LeftChar=1
29+
[Editor_5]
30+
CursorCol=1
31+
CursorRow=16
32+
TopLine=3
33+
LeftChar=1
34+
[Editor_6]
35+
CursorCol=23
36+
CursorRow=53
37+
TopLine=37
38+
LeftChar=1
39+
[Editor_8]
40+
CursorCol=27
41+
CursorRow=76
42+
TopLine=61
43+
LeftChar=1
44+
[Editor_7]
45+
CursorCol=21
46+
CursorRow=80
47+
TopLine=69
48+
LeftChar=1
49+
[Editor_9]
50+
CursorCol=3
51+
CursorRow=60
52+
TopLine=79
53+
LeftChar=1

adjacency_list.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "constant.h"
4+
5+
6+
pNode CreateNode(int d, double val)
7+
{
8+
pNode newNode;
9+
newNode = (pNode)malloc(sizeof(Node));
10+
newNode->vertex = d;
11+
newNode->cost = val;
12+
newNode->next = NULL;
13+
return newNode;
14+
}
15+
16+
pGraph CreateGraph(int vertices)
17+
{
18+
19+
pGraph newGraph;
20+
newGraph = (pGraph)malloc(sizeof(Graph));
21+
22+
newGraph->numVertices = vertices;
23+
24+
newGraph->lists = (pNode *)malloc((vertices+1) * sizeof(pNode));
25+
26+
int i;
27+
pNode temp;
28+
for (i = 1; i <= vertices; i++)
29+
{
30+
temp = CreateNode(i, 0);
31+
newGraph->lists[i] = temp;
32+
}
33+
34+
return newGraph;
35+
}
36+
void AddEdge(pGraph graph, int s, int d, double val)
37+
{
38+
39+
pNode newNode = CreateNode(d, val);
40+
41+
newNode->next = graph->lists[s]->next;
42+
43+
graph->lists[s]->next = newNode;
44+
45+
}
46+
47+
pGraph MatrixToList(FILE *f, int *sign)
48+
{
49+
int n,tp;
50+
f=fopen(LINK,"r");
51+
if (fscanf(f,"%d",&n)==EOF || n<=1)
52+
{
53+
printf("Data file is not valid. End program!");
54+
exit(0);
55+
}
56+
pGraph graph = CreateGraph(n);
57+
double val;
58+
pNode temp;
59+
for (int i = 1; i <= n; i++)
60+
{
61+
for (int j=1;j<=n;j++)
62+
{
63+
if (i==j)
64+
{
65+
if (fscanf(f,"%lf", &val)==0 || val!=0)
66+
{
67+
printf("Data file is not valid. End program!");
68+
system("pause");
69+
exit(0);
70+
}
71+
continue;
72+
}
73+
if (fscanf(f,"%lf", &val)==0)
74+
{
75+
printf("Data file is not valid. End program!");
76+
system("pause");
77+
exit(0);
78+
}
79+
if(val<0) *sign=1;
80+
if (val<MAXC) AddEdge(graph,i,j,val);
81+
}
82+
}
83+
char last[256];
84+
fscanf(f,"%[ \n]s",last);
85+
if (!feof(f))
86+
{
87+
printf("Data file is not valid. End program!");
88+
system("pause");
89+
exit(0);
90+
}
91+
fclose(f);
92+
return graph;
93+
}

adjacency_list.o

2.73 KB
Binary file not shown.

constant.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef constant
2+
#define constant
3+
#define MAXC 1e108 //no direct path
4+
#define MAX 10000 //max number of vertices
5+
//#define LINK "matrix.txt"
6+
#define ERR "Warning! Please enter valid data\n\n"
7+
#define LINE "*****************************0o0***************************\n"
8+
extern char LINK[100];
9+
typedef struct node
10+
{
11+
int vertex;
12+
double cost;
13+
struct node *next;
14+
} Node;
15+
typedef Node *pNode;
16+
17+
typedef struct
18+
{
19+
int numVertices;
20+
pNode *lists;
21+
} Graph;
22+
typedef Graph *pGraph;
23+
#endif
24+
25+

0 commit comments

Comments
 (0)