Last change
on this file since 10677 was
6152,
checked in by bfarka, 14 years ago
|
added ecj and custom statistics to communicate with the okb services #1441
|
File size:
2.0 KB
|
Line | |
---|
1 | package ec.gp.ge;
|
---|
2 | import java.util.*;
|
---|
3 | import ec.gp.*;
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * GrammarFunctionNode.java
|
---|
7 | *
|
---|
8 | * Created: Sun Dec 5 11:33:43 EST 2010
|
---|
9 | * By: Houston Mooers and Sean Luke
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * A GrammarNode representing a GPNode in the GE Grammar. The head of the GrammarFunctionNode
|
---|
15 | * is the name of the GPNode in the grammar; and the children are various arguments to the node
|
---|
16 | * as defined by the grammar. These are returned by getArgument(...) and getNumArguments().
|
---|
17 | * The GrammarFunctionNode holds a prototypical GPNode from which clones can be made.
|
---|
18 | *
|
---|
19 | */
|
---|
20 |
|
---|
21 | public class GrammarFunctionNode extends GrammarNode
|
---|
22 | {
|
---|
23 | GPNode prototype;
|
---|
24 |
|
---|
25 | /** Determines the GPNode from the function set by the name. If there is more than
|
---|
26 | one such node (which shouldn't be the case) then only the first such node is
|
---|
27 | used. Stores the prototype. */
|
---|
28 |
|
---|
29 | public GrammarFunctionNode(GPFunctionSet gpfs, String name)
|
---|
30 | {
|
---|
31 | super(name);
|
---|
32 | prototype = ((GPNode[]) (gpfs.nodesByName.get(name)))[0];
|
---|
33 | }
|
---|
34 |
|
---|
35 | /** Adds a given argument to the node. */
|
---|
36 | public void addArgument(GrammarNode arg)
|
---|
37 | {
|
---|
38 | children.add(arg);
|
---|
39 | }
|
---|
40 |
|
---|
41 | /** Returns the number of arguments. */
|
---|
42 | public int getNumArguments() { return children.size(); }
|
---|
43 |
|
---|
44 | /** Returna given argument. */
|
---|
45 | public GrammarNode getArgument(int index) { return (GrammarNode)(children.get(index)); }
|
---|
46 |
|
---|
47 | /** Returns the prototype without cloning it first. Be certain to clone before using. */
|
---|
48 | public GPNode getGPNodePrototype() { return prototype; }
|
---|
49 |
|
---|
50 | public String toString()
|
---|
51 | {
|
---|
52 | String ret = "(" + head + " ";
|
---|
53 | Iterator i = children.iterator();
|
---|
54 | boolean first = true;
|
---|
55 | while(i.hasNext())
|
---|
56 | {
|
---|
57 | ret = ret + (first ? "" : " ") + ((GrammarNode)(i.next())).getHead();
|
---|
58 | first = false;
|
---|
59 | }
|
---|
60 | return ret + ")";
|
---|
61 | }
|
---|
62 |
|
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.