-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathedaopt.h
More file actions
78 lines (74 loc) · 2.52 KB
/
edaopt.h
File metadata and controls
78 lines (74 loc) · 2.52 KB
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
/*
* moses/moses/main/edaopt.h
*
* Copyright (C) 2002-2008 Novamente LLC
* All Rights Reserved
*
* Written by Moshe Looks
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License v3 as
* published by the Free Software Foundation and including the exceptions
* at http://opencog.org/wiki/Licenses
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, write to:
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <assert.h>
#include <iostream>
#include <vector>
#include <boost/lexical_cast.hpp>
using namespace std;
// WARNING: the additional arguments must be handled by the caller,
// but it is done here for checking and usage printing.
// This is an ugly but quick fix for the demo programs.
struct optargs
{
optargs(int argc, char** argv,
const vector<string>& additional_args = vector<string>()) {
if (argc != (5 + static_cast<int>(additional_args.size()))) {
cerr << "Error: wrong number of args.\n"
<< "Usage: " << argv[0]
<< " <rand seed> <length> <population size> <num generations> "
<< usage(additional_args) << endl;
exit(1);
}
try {
assert(argc >= 5);
rand_seed = boost::lexical_cast<int>(argv[1]);
length = boost::lexical_cast<int>(argv[2]);
popsize = boost::lexical_cast<int>(argv[3]);
n_select = popsize;
n_generate = popsize/2;
max_gens = boost::lexical_cast<int>(argv[4]);
} catch (...) {
cerr << "Error: invalid argument\nUsage: " << argv[0]
<< " <rand seed> <length> <population size> <num generations> "
<< usage(additional_args) << endl;
exit(1);
}
}
int rand_seed;
int length;
int popsize;
int n_select;
int n_generate;
int max_gens;
private:
string usage(const vector<string>& args)
{
string res;
for (vector<string>::const_iterator i = args.begin();
i != args.end(); ++i) {
res += *i + string(" ");
}
return res;
}
};