Var
From CometPublic
[edit] Integer Variables
A comet integer variable (incremental variable) can be created with a statement
var{int} x(m);
where m is an instance of type LocalSolver. The variable is an instance of a comet class with the following API
class var{int} {
void exclud();
void includ();
int getId();
int getOld();
int getSnapshot(Solution);
set{int} getDomain();
LocalSolver getLocalSolver();
void setDomain(set{int});
}
Once again, x can respond to any method invocation in this API.
- exclud() request that the variable be excluded from any solution object obtained from the local solver
- includ() request that the variable be included (the default) in any solution object obtained from the local solver.
- getId() returns the identifier of the variable (an integer in the range 0..N) where N is the number of variables created explicitely or implicitly.
- getOld() internal use only
- getSnapshot(Solution) looks up the value of the variable (receiver) in the solution object passed as an argument.
- getDomain() retrieves the domain of the variable (a range)
- setDomain(set{int}) imposes a domain on the variable (the variable should always be assigned a value from its domain)
- getLocalSolver() retrieves the solver in which the variable has been created (a variable always belongs to exactly one solver)
The @changes() event can be used to trigger the execution of a code block every time the variable changes:
whenever x@changes() {
cout << "before : " << x.getOld() << " after " << x << endl;
}
The "when", "foreveron" and "whenever" keywords can be used. When using "when" the code block is executed on the next occurence of the event. "whenever" executes it for any subsequent occurence of the event and finally, "foreveron" executes it once right now and once for every subsequent change to the variable x.
[edit] Set Variables
Set variables can be instantiated via the statement
var{set{int}} s(m);
where, as above, m is an instance of LocalSolver. These variables come with the following API:
class var{set{int}} {
void includ();
void exclude();
int getId();
void insert(int);
void delete(int);
}
the cardinality of a set variable can be obtained via the statement
card(s)
membership in a set variable can be obtained via the statement
member(v,s)
The @insert(int i) and @remove(int i) can be used with sets. They can only be used with "when" and "whenever", not "foreveron". An example follows:
whenever s@insert(int v)
cout << v << " was added to " << s << endl;
[edit] Float Variables
var{float} f(m);
where, as above, m is an instance of LocalSolver. These variables come with the following API:
class var{float} {
void includ();
void exclude();
int getId();
void getSnapshot(Solution);
}
The @changes(float old, float n) can be used with floats. They can only be used with "when" and "whenever", not "foreveron". An example follows:
whenever f@changes(float old, float n)
cout << old << " changed to " << n << endl;

