53size_t getn(
const std::string& strBanner){
54 std::cout << strBanner << std::endl <<
"> ";
56 std::getline(std::cin, strLine);
58 return (
size_t)std::stoi(strLine);
75 case 3:
case 4: ok = d == 2 || d == 3;
break;
76 case 5:
case 6: ok = d == 4 || d == 5;
break;
77 case 7:
case 8: ok = d == 5 || d == 6;
break;
78 case 9:
case 10: ok = d == 6 || d == 7;
break;
79 case 11:
case 12: ok = d == 7 || d == 8;
break;
84 std::cout <<
"Depth must be ";
87 case 3:
case 4: std::cout <<
"2 or 3";
break;
88 case 5:
case 6: std::cout <<
"4 or 5";
break;
89 case 7:
case 8: std::cout <<
"5 or 6";
break;
90 case 9:
case 10: std::cout <<
"6 or 7";
break;
91 case 11:
case 12: std::cout <<
"7 or 8";
break;
94 std::cout << std::endl;
112 n =
getn(
"Enter number of inputs. Must be at least 3 and at most 12.");
113 ok = n >= 3 && n <= 12;
114 if(!ok)std::cout <<
"Out of range" << std::endl;
122 d =
getn(
"Enter depth.");
123 ok = d >= 3 && d <= 8;
124 if(!ok)std::cout <<
"Out of range" << std::endl;
137 std::cout <<
"Use nearsort2 heuristic? [yn]" << std::endl <<
"> ";
139 std::getline(std::cin, strLine);
140 bNearsort2 = strLine[0] ==
'y' || strLine[0] ==
'Y';
151 std::cout << s << std::endl;
155 std::ofstream logfile(
"log.txt", std::ios::app);
156 logfile << s << std::endl;
177 for(
auto matching: L2Matchings){
181 case 2: pSearch =
new C2NF(matching, i++);
break;
183 case 4: pSearch =
new CNearsort(matching, i++);
break;
187 else pSearch =
new CNearsort(matching, i++);
191 p->Insert(
new CTask(pSearch));
200 delete pLevel2Search;
216 bool bFastGrayCode =
false;
217 bool bNearsort2 =
false;
220 CTimer* pTimer =
new CTimer;
224 std::cout <<
"Start " << pTimer->GetTimeAndDate() << std::endl;
226 std::string strSummary =
"Searching for " +
227 std::to_string(nWidth) +
"-input sorting networks of depth " +
228 std::to_string(nDepth);
237 Search(pThreadManager, nDepth, bNearsort2);
241 std::cout <<
"Finish " << pTimer->GetTimeAndDate() << std::endl;
243 strSummary = std::to_string(pThreadManager->
GetCount()) +
" found in " +
244 pTimer->GetElapsedTime() +
" using " +
245 pTimer->GetCPUTime() +
" CPU time over " +
246 std::to_string(pThreadManager->GetNumThreads()) +
" threads";
252 delete pThreadManager;
void SaveSummary(const std::string s)
Save summary string.
size_t getn(const std::string &strBanner)
Get size_t from input.
void Search(CThreadManager *p, const size_t nDepth, const bool bNearsort2)
Multi-threaded search.
bool CheckParams(const size_t n, const size_t d)
Check that depth is reasonable for width.
void ReadParams(size_t &n, size_t &d)
Read parameters for search.
Header for the task class CTask.
Interface for the ternary reflected Gray code generator CTernaryGrayCode.
Header for the thread manager CThreadManager.
Second normal form searchable sorting network.
Searchable second normal form sorting network with autocomplete.
const std::vector< CMatching > & GetMatchings() const
Get matching vector.
Searchable sorting network with nearsort2.
Searchable sorting network with nearsort.
Searchable sorting network.
static void SetWidth(const size_t)
Set width.
static void SetDepth(const size_t)
Set depth.
const size_t GetCount() const
Get count.