Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/rule/RuleConstraints.java @ 6152

Last change on this file since 6152 was 6152, checked in by bfarka, 13 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 2.6 KB
Line 
1/*
2  Copyright 2006 by Sean Luke and George Mason University
3  Licensed under the Academic Free License version 3.0
4  See the file "LICENSE" for more information
5*/
6
7
8package ec.rule;
9import ec.*;
10import ec.util.*;
11
12/*
13 * RuleConstraints.java
14 *
15 * Created: Tue Feb 20 13:16:00 2001
16 * By: Liviu Panait and Sean Luke
17 */
18
19/**
20 * RuleConstraints is a class for constraints applicable to rules.
21 * You can subclass this to add additional constraints information
22 * for different kinds of rules.
23 *
24 * @author Liviu Panait and Sean Luke
25 * @version 1.0
26
27 <p><b>Parameters</b><br>
28 <table>
29 <tr><td valign=top><i>base</i>.<tt>size</tt><br>
30 <font size=-1>int &gt;= 1</font></td>
31 <td valign=top>(number of rule constraints)</td></tr>
32
33 <tr><td valign=top><i>base.n</i>.<tt>name</tt><br>
34 <font size=-1>String</font></td>
35 <td valign=top>(name of rule constraint <i>n</i>)</td></tr>
36 </table>
37
38*/
39public class RuleConstraints implements Clique
40    {
41//    public static final int SIZE_OF_BYTE = 256;
42    public final static String P_NAME = "name";
43//    public final static String P_SIZE = "size";
44
45    /** The byte value of the constraints -- we can only have 256 of them */
46    public byte constraintNumber;
47
48    /** The name of the RuleConstraints object */
49    public String name;
50
51    /** Converting the rule to a string ( the name ) */
52    public String toString() { return name; }
53
54
55    public void setup(final EvolutionState state, final Parameter base)
56        {
57        // What's my name?
58        name = state.parameters.getString(base.push(P_NAME),null);
59        if (name==null)
60            state.output.fatal("No name was given for this Rule Constraints.",
61                base.push(P_NAME));
62
63        // Register me
64        RuleConstraints old_constraints = (RuleConstraints)(((RuleInitializer)state.initializer).ruleConstraintRepository.put(name,this));
65        if (old_constraints != null)
66            state.output.fatal("The rule constraints \"" + name + "\" has been defined multiple times.", base.push(P_NAME));
67        }
68
69    /** You must guarantee that after calling constraintsFor(...) one or
70        several times, you call state.output.exitIfErrors() once. */
71
72    public static RuleConstraints constraintsFor(final String constraintsName,
73        final EvolutionState state)
74        {
75        RuleConstraints myConstraints = (RuleConstraints)(((RuleInitializer)state.initializer).ruleConstraintRepository.get(constraintsName));
76        if (myConstraints==null)
77            state.output.error("The rule constraints \"" + constraintsName + "\" could not be found.");
78        return myConstraints;
79        }
80    }
Note: See TracBrowser for help on using the repository browser.