Browse Source

update engine

master
Dnomd343 4 years ago
parent
commit
4fbe402107
  1. 42
      src/engine/HRD_analy.cpp
  2. 4
      src/engine/HRD_analy.h
  3. 106
      src/engine/main.cpp

42
src/engine/HRD_analy.cpp

@ -100,7 +100,7 @@ void HRD_analy::Output_Graph(unsigned long long code, unsigned int square_width,
cout << endl;
}
bool HRD_analy::Get_Path(vector <unsigned long long> target, string File_name) {
bool HRD_analy::Output_Path(vector <unsigned long long> target, string File_name) {
Case_cal *address;
unsigned int i, j, k, num;
struct Highlight_point {
@ -181,6 +181,34 @@ bool HRD_analy::Search_Case(unsigned long long code, Case_cal* &dat) {
return false;
}
void HRD_analy::Output_All_Path(string File_name) {
ofstream output;
unsigned int i, j, k;
output.open(File_name);
output << "[Target]" << endl;
output << "[Layer]" << endl;
for (i = 0; i < Layer.size(); i++) {
for (j = 0; j < Layer[i].size(); j++) {
output << "(" << i << "," << j << ") = ";
output << Change_str((*Layer[i][j]).code) << endl;
}
}
vector <Case_cal *> *case_list;
output << "[Next]" << endl;
for (i = 0; i < Layer.size(); i++) {
for (j = 0; j < Layer[i].size(); j++) {
case_list = Layer[i][j]->next_case;
output << "(" << i << "," << j << ") ->";
for (k = 0; k < case_list->size(); k++) {
output << " (" << (*case_list->at(k)).layer_num;
output << "," << (*case_list->at(k)).layer_index << ")";
}
output << endl;
}
}
output.close();
}
void HRD_analy::Output_Detail(string File_name) { // 输出分析结果到文件
unsigned int i, j, k;
ofstream output;
@ -255,6 +283,7 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
vector < vector <bool> > solution_flag;
vector <unsigned long long> temp;
unsigned int i, j, k;
stop_point_num = 0;
farthest_step = -1; // 初始化farthest
farthest_num = 0;
farthest_case.clear();
@ -277,6 +306,14 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
}
farthest_num = farthest_case.size();
sort(farthest_case.begin(), farthest_case.end()); //得到的结果进行排序
// 获取端点个数
for (i = 0; i < Layer.size(); i++) {
for (j = 0; j < Layer[i].size(); j++) {
if (Layer[i][j]->next_case->size() == 0) {
stop_point_num++;
}
}
}
// 获取最少步解
for (i = 0; i < Layer.size(); i++) {
for (j = 0; j < Layer[i].size(); j++) {
@ -327,9 +364,10 @@ void HRD_analy::Analyse_Case(unsigned long long code) { // 分析输入编码的
}
}
solution_num = solution_case.size();
if (quiet) {return;} // 若quiet为true则不输出
cout << "---------------------------" << endl;
cout << "stop_point_num = " << stop_point_num << endl;
cout << "---------------------------" << endl;
cout << "farthest_step = " << farthest_step << endl;
cout << "farthest_num = " << farthest_num << endl;
cout << "farthest_case -> " << endl;

4
src/engine/HRD_analy.h

@ -22,6 +22,7 @@ class HRD_analy {
Case_cal Parse_dat;
bool quiet = false; // true -> 静默模式 false -> 输出运算情况
// 布局的基本参数
int stop_point_num; // 端点的个数
int min_solution_step; // 最少的步数
int min_solution_num; // 最少步解的个数
vector <unsigned long long> min_solution_case; // 所有最少步解
@ -39,8 +40,9 @@ class HRD_analy {
bool Is_Mirror(unsigned long long code);
void Analyse_Case(unsigned long long code);
void Output_Detail(string File_name);
bool Get_Path(vector <unsigned long long> target, string File_name);
void Free_Data();
void Output_All_Path(string File_name);
bool Output_Path(vector <unsigned long long> target, string File_name);
void Output_Graph(unsigned long long code, unsigned int square_width, unsigned int square_gap, char str[2]);
private:

106
src/engine/main.cpp

@ -154,7 +154,53 @@ void cal_path(string code_str, string File_name) {
for (unsigned int i = 0; i < analy.min_solution_case.size(); i++) {
cout << " " << analy.Change_str(analy.min_solution_case[i]) << endl;
}
analy.Get_Path(analy.min_solution_case, File_name);
analy.Output_Path(analy.min_solution_case, File_name);
cout << "Data save at " << File_name << endl;
}
void cal_solution_path(string code_str, string File_name) {
unsigned long long code;
if (code_check(code_str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
HRD_analy analy;
analy.quiet = true;
if (File_name == "%") {File_name = analy.Change_str(code) + ".txt";}
cout << "Start code: " << analy.Change_str(code) << endl;
analy.Analyse_Case(code);
if (analy.min_solution_step == -1) {
cout << "no solution" << endl;
return;
}
cout << "solution case(" << analy.solution_num <<"):" << endl;
for (unsigned int i = 0; i < analy.solution_case.size(); i++) {
cout << " " << analy.Change_str(analy.solution_case[i]) << "(" << analy.solution_step[i] << ")" << endl;
}
analy.Output_Path(analy.solution_case, File_name);
cout << "Data save at " << File_name << endl;
}
void cal_farthest_path(string code_str, string File_name) {
unsigned long long code;
if (code_check(code_str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
HRD_analy analy;
analy.quiet = true;
if (File_name == "%") {File_name = analy.Change_str(code) + ".txt";}
cout << "Start code: " << analy.Change_str(code) << endl;
analy.Analyse_Case(code);
cout << "farthest case(" << analy.farthest_num <<"):" << endl;
for (unsigned int i = 0; i < analy.farthest_case.size(); i++) {
cout << " " << analy.Change_str(analy.farthest_case[i]) << endl;
}
analy.Output_Path(analy.farthest_case, File_name);
cout << "Data save at " << File_name << endl;
}
@ -256,7 +302,7 @@ void cal_target_path(string code_str, vector <string> target_dat, string File_na
cout << " " << analy.Change_str(target[i]) << endl;
}
analy.Analyse_Case(code);
if (analy.Get_Path(target, File_name)) {
if (analy.Output_Path(target, File_name)) {
cout << "Data save at " << File_name << endl;
} else {
cout << "Target not found" << endl;
@ -307,6 +353,24 @@ void cal_group(string code_str, string File_name) {
File_Output.close();
}
void cal_group_path(string code_str, string File_name) {
unsigned long long code;
if (code_check(code_str) == false) {
cout << "code error" << endl;
cout << endl;
return;
}
code = checked_code;
HRD_analy analy;
analy.quiet = true;
if (File_name == "%") {File_name = analy.Change_str(code) + ".txt";}
cout << "Start code: " << analy.Change_str(code) << endl;
analy.Analyse_Case(code);
cout << "stop_point_num: " << analy.stop_point_num << endl;
analy.Output_All_Path(File_name);
cout << "Data save at " << File_name << endl;
}
void analy_case(string code_str, bool quiet) {
unsigned long long code;
vector <unsigned long long> dat;
@ -434,6 +498,14 @@ void show_help() {
cout << " Purpose: Find all of the minimum step solution path of <code>" << endl;
cout << " eg: ./engine --cal-path 4FEA13400 demo.txt" << endl;
cout << endl;
cout << " --cal-solution-path <code> <file_name>" << endl;
cout << " Purpose: Find all of the solution path of <code>" << endl;
cout << " eg: ./engine --cal-solution-path 1A9BF0C00 demo.txt" << endl;
cout << endl;
cout << " --cal-farthest-path <code> <file_name>" << endl;
cout << " Purpose: Find all of the farthest path of <code>" << endl;
cout << " eg: ./engine --cal-farthest-path 4FEA13400 demo.txt" << endl;
cout << endl;
cout << " --cal-target-path <code> <target_1> ... <target_n> <file_name>" << endl;
cout << " Purpose: Find all of the shortest path from <code> to <target_1>...<target_n>" << endl;
cout << " eg: ./engine --cal-target-path 1A9BF0C00 DAAF4CC00 AE2F2B400 demo.txt" << endl;
@ -443,6 +515,10 @@ void show_help() {
cout << " eg: ./engine --group 4FEA13400" << endl;
cout << " ./engine --group 4FEA13400 demo.txt" << endl;
cout << endl;
cout << " --group-path <code> <file_name>" << endl;
cout << " Purpose: Find all of the path in the group where <code> located" << endl;
cout << " eg: ./engine --group-path 1A9BF0C00 demo.txt" << endl;
cout << endl;
cout << " --analy <code> [file_name]" << endl;
cout << " Purpose: Detailed analysis of the <code> " << endl;
cout << " eg: ./engine --analy 1A9BF0C00" << endl;
@ -520,17 +596,29 @@ int main(int argc, char* argv[]) {
} else {
parameter_err();
}
} else if (parameter == "--cal-target") {
if (argc == 4) {
cal_target(argv[2], argv[3]);
} else if (argc == 5) {
cal_target(argv[2], argv[3], argv[4]);
} else {
parameter_err();
}
} else if (parameter == "--cal-path") {
if (argc == 4) {
cal_path(argv[2], argv[3]);
} else {
parameter_err();
}
} else if (parameter == "--cal-target") {
} else if (parameter == "--cal-solution-path") {
if (argc == 4) {
cal_target(argv[2], argv[3]);
} else if (argc == 5) {
cal_target(argv[2], argv[3], argv[4]);
cal_solution_path(argv[2], argv[3]);
} else {
parameter_err();
}
} else if (parameter == "--cal-farthest-path") {
if (argc == 4) {
cal_farthest_path(argv[2], argv[3]);
} else {
parameter_err();
}
@ -552,6 +640,12 @@ int main(int argc, char* argv[]) {
} else {
parameter_err();
}
} else if (parameter == "--group-path") {
if (argc == 4) {
cal_group_path(argv[2], argv[3]);
} else {
parameter_err();
}
} else if (parameter == "--analy") {
if (argc == 3) {
analy_case(argv[2], false);

Loading…
Cancel
Save