FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Genetic-String-Mapping-Algorithm/src/MainFile.cpp at main · vatsalcode/Genetic-String-Mapping-Algorithm · GitHub
vatsalcode
/
Genetic-String-Mapping-Algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Genetic-String-Mapping-Algorithm
/
src
/
MainFile.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (96 loc) · 3.01 KB
Breadcrumbs
Genetic-String-Mapping-Algorithm
/
src
/
MainFile.cpp
Copy path
File metadata and controls
112 lines (96 loc) · 3.01 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#
include
"
../include/GeneSequence.h
"
extern
time_t
startingTime, currentTime;
extern
int
timeLimit;
extern
vector<string> answerReport;
extern
int
costReport;
extern
bool
reversed;
extern
bool
answerReverse;
int
main
(
int
argc,
char
*argv[]){
//
cout<<argc<<endl;
//
return 0;
if
(argc ==
3
){
string
inputFileName
(argv[
1
]);
string
outputFileName
(argv[
2
]);
ifstream
inputFile
(inputFileName);
string line;
time_t
timestart, timeend;
int
vsize, k, cc, i, j;
float
execTime;
string tempString;
vector<string> myStrings;
vector<vector<
int
> > costMap;
vector<
int
> goalTuple;
vector<
int
> zeroTuple;
char
dumpComma;
inputFile >> execTime;
//
cout<<line<<endl; // input for the time limit of the runtime of the code
inputFile >> vsize;
//
input for vocabulary size and its letters
vector<
char
>
myVocabulary
(vsize,
'
*
'
);
int
tempIndex =
0
;
for
(i =
0
; i < vsize-
1
; i++){
inputFile >> myVocabulary[i] >> dumpComma;
tempIndex = tempIndex +
3
;
}
inputFile >> myVocabulary[i];
myVocabulary.
push_back
(
'
-
'
);
//
for(int i=0;i<myVocabulary.size();i++){
//
cout<<myVocabulary[i]<<" " << vsize << endl;
//
}
//
cout<<endl;
inputFile >> k;
//
input for number of strings and the strings
for
(i =
0
; i < k; i++){
inputFile >> tempString;
//
tempString.erase(remove(tempString.begin(), tempString.end(),' '), tempString.end());
myStrings.
push_back
(tempString);
goalTuple.
push_back
(tempString.
length
());
zeroTuple.
push_back
(
0
);
}
inputFile >> cc;
//
input for conversion cost
string falseString;
int
tempInt;
//
input for matching cost matrix
for
(i =
0
; i < vsize +
1
; i++) {
vector<
int
> tempVector;
//
getline(inputFile, line);
tempIndex =
0
;
for
(j =
0
; j < vsize +
1
; j++){
inputFile >> tempInt;
//
tempIndex = tempIndex + 2;
tempVector.
push_back
(tempInt);
}
costMap.
push_back
(tempVector);
}
//
for(int i=0;i<costMap.size();i++){
//
for(int j=0;j<costMap[0].size();j++){
//
cout<<costMap[i][j]<<" ";
//
}
//
cout<<endl;
//
}
char
hash;
inputFile.
close
();
time
(×tart);
startingTime = timestart;
timeLimit = (
int
)(execTime *
60
-
5
);
GeneSequence* genes =
new
GeneSequence
(vsize +
1
, myVocabulary, k, myStrings, cc, costMap);
HillClimbingState
startState
(myStrings);
int
maxlen = genes->
maxStringLength
(myStrings) +
15
;
int
finalCost1 = genes->
localSearch
(startState, maxlen);
for
(
int
i =
0
; i < k; i++)
reverse
(startState.
orientation
[i].
begin
(), startState.
orientation
[i].
end
());
reversed =
1
;
int
finalCost2 = genes->
localSearch
(startState, maxlen);
answerReport = genes->
balanceStrings
(answerReport);
ofstream
outputFile
(outputFileName);
for
(
int
i=
0
;i<answerReport.
size
();i++){
if
(answerReverse){
reverse
(answerReport[i].
begin
(), answerReport[i].
end
());
}
outputFile << answerReport[i] << endl;
}
cout <<
"
The cost value is:
"
<< costReport << endl;
time
(&timeend);
}
else
{
cerr<<
"
Wrong Arguments
"
<<endl;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL