-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcl_print.cpp
70 lines (55 loc) · 1.84 KB
/
cl_print.cpp
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
//cl_ga.cpp
/*
Copyright (C) 2013 AIDEUS
authors: Sergey Rodionov (astroseger@gmail.com)
Alexey Potapov (potapov@aideus.com)
aideus.com
This file is part of cl-lab.
cl-lab is released under the GNU General Public License (GNU GPL).
Please read the included file COPYING for more information.
*/
//the first version of genetic algorithms
#include "sp_parmap.h"
#include "cl_ga_tools.h"
#include "cl_brute.h"
#include <algorithm>
const char* defv[] = {
"in=\n Input string",
"ignore=I\n Symbols to ignore in result",
"lout=1000\n number of symbols to print",
"max_mem=10000000\n Maximal memory consumation during a computation (nterms)",
"max_steps=10000000\n Maximal reduction steps during a computation",
"is_stepmode=0\n Step by step mode",
NULL
};
int main(int argc, char*argv[])
{
sp_parmap p(argc, argv, defv);
size_t max_steps = p.get_i("max_steps");
size_t max_mem = p.get_i("max_mem");
int counter = 0; //global counter
cl_term term(p.get_s("in"), &counter);
if (p.get_b("is_stepmode"))
{
for (size_t i = 0 ; i < max_steps ; i++)
{
int c = term.reduce_all(1, max_mem);
cout<<term.conv2str()<<endl<<endl;
if (c != -2) //not a step limit
return 0;
}
return 0;
}
int code = term.reduce_all(p.get_i("max_steps"), p.get_i("max_mem"));
cout<<"return code="<<code<<endl;
string rez = term.conv2str(p.get_i("lout"));
string rezi;
string ignore = p.get_s("ignore");
for (size_t i = 0 ; i < rez.size() ; i++)
if (ignore.find(rez[i]) == string::npos )
if (rez[i] != '(' && rez[i] != ')')
rezi.push_back(rez[i]);
cout<<rez<<endl<<endl;
cout<<rezi<<endl<<endl;
}
//