For anyone who is interested, params generated at runtime, some pros: partial checks IDE/compile, add/remove functions easily,
public class Tutorial4 extends Evolve {
private static HashMap<String, Object> paramList;
public static void main(String[] args) {
Class[] func = {
Add.class,
Mul.class,
Sub.class,
X.class,
Y.class
};
paramList = new HashMap<>();
// not posible Evolve.java requires a file, might as well give them the parent
// paramList.put("parent.0", "../../gp/koza/koza.params");
addFunctions(func);
// function definitions
paramList.put("gp.fs.size", "1");
paramList.put("gp.fs.0", GPFunctionSet.class);
// problem and data
paramList.put("eval.problem", MultiValuedRegression.class);
paramList.put("eval.problem.data", DoubleData.class);
String[] params = new String[(paramList.size() + 1) * 2];
int i = 0; // index
params[i] = "-file"; i++;
params[i] = "parent.params"; i++;
for(String key: paramList.keySet()) {
params[i] = "-p"; i++;
if(paramList.get(key) instanceof String)
params[i] = key + "=" + paramList.get(key);
else params[i] = key + "=" + paramList.get(key).toString().split(" ")[1];
i++;
}
// for(String p: params) System.out.println(p);
Evolve.main(params);
}
public static void addFunctions(Class[] classList) {
paramList.put("gp.fs.0.size", classList.length + "");
for(int i = 0; i < classList.length; i ++) {
paramList.put("gp.fs.0.func." + i, classList[i].toString().split(" ")[1]);
// TODO fix this, do some checks
GPNode node = null;
try { node = (GPNode) classList[i].newInstance(); }
catch(Exception e) { e.printStackTrace(); }
paramList.put("gp.fs.0.func." + i + ".nc", "nc" + node.expectedChildren());
}
}
}
---------- Forwarded message ----------
From:
Sean Luke <[log in to unmask]>Date: Fri, Jun 21, 2013 at 10:59 AM
Subject: Re: ECJ Design: param files vs code based parameters
To: Vlad Palnik <
[log in to unmask]>
It is certainly possible, but you'd have to hijack the setup method to set up things how you see fit rather than have the default method load from the database.
Sean
On Jun 20, 2013, at 8:15 PM, Vlad Palnik wrote:
> Sean,
>
> Question regarding a road not taken,
>
> I have a very large function set and a single change requires editing the entire parameter list.
>
> I'm adding function specific parameters (return type/children type/number of children) directly to the function code, I know the system
> was designed to use text based parameters so currently the parameters files are generated before I run a simulation.
>
> I would like to set up the system to load the GPNodeConstraints parameters directly from the functions, is this something I can do quickly??
>
> Was there a specific reason function parameters are loaded from a file and do you foresee any problems when I try to implement this??
>
> Vlad Palnik