Algorithm::CP::IZ::Int - Domain variable for Algorithm::CP::IZ
use Algorithm::CP::IZ; my $iz = Algorithm::CP::IZ->new(); # create instances of Algorithm::CP::IZ::Int # contains domain {0..9} my $v1 = $iz->create_int(1, 9); my $v2 = $iz->create_int(1, 9); # add constraint $iz->Add($v1, $v2)->Eq(12); # get current status print $v1->nb_elements, "\n2; # print domain print "$v1\n";
Algorithm::CP::IZ::Int is perl representation of CSint object in iZ-C library. This class is called also 'domain variable'.
Domain is a set of candidate values of solution which can satisfy current constraint setting.
You can declare range of domain (which integer is in domain) when creating variable. Variable can take values 1..9 (1..9 is in domain) in following example.
my $var = $iz->create_int(1, 9);
Values will be removed by applying constraint. For example, After applying constraint $var->Le(3) to above example variable, domain of $var is 1..3.
$var->Le(3); # $var <= 3 (6..9 is removed from domain) print "$var\n"; # Output will be "{1..3}".
If domain variable has more than one value, it is calld 'free'.
my $rc = $var->is_free; # $rc is 1
If domain has just one value, it is calld 'instantiated'.
$rc = $var->is_instantiated; # $rc is 1
If all domain variables are instantiated satisfing constraints, variables represent solution of input problem.
If All values are removed from domain, it is assumed as "fail". (no solution is found under current constraint setting)
All constraint method returns 1 (OK) or 0 (fail).
$rc = $var->Le(0); # fail print "$rc\n"; # Output will be 0.
Create string representation of this variable. ('""' operator has overloaded to call this method.)
Returns string to use hash key. Don't use following code. (stringify-ed string is not unique!)
%hash{$v} = "something";
Use this:
%hash{$v->key} = "something";
Get name of this variable.
Set name of this variable.
Returns count of values in domain.
Returns minimum value of domain.
Returns maximum value of domain.
Returns instantiated value of this variable.
If this method called for not instancited variable, exception will be thrown.
Returns 1 (domain has more than 1 value) or 0 (domain has 1 only value).
Returns 1 (instantiated, it means domain has only 1 value) or 0 (domain has more than 1 value).
Returns array reference of domain values.
Returns a value next value of X in domain. (If domain is {0, 1, 2, 3} and X is 1, next value is 2)
X is an integer value.
Returns a value previous value of X in domain. (If domain is {0, 1, 2, 3} and X is 2, next value is 1)
Returns 1 (X is in domain) or 0 (X is not in domain)
Constraints this variable "equal to X". X is an integer or an instance of Algorithm::CP::IZ::Int.
Constraints this variable "not equal to X". X is an integer or an instance of Algorithm::CP::IZ::Int.
Constraints this variable "less or equal to X". X is an integer or an instance of Algorithm::CP::IZ::Int.
Constraints this variable "less than X". X is an integer or instance of Algorithm::CP::IZ::Int.
Constraints this variable "greater or equal to X". X is an integer or instance of Algorithm::CP::IZ::Int.
Constraints this variable "greater than X". X is an integer or an instance of Algorithm::CP::IZ::Int.
Constraints this variable to be element of arrayref.
Constraints this variable not to be element of arrayref.
Constraints this variable to be range MIN to MAX.
Constraints this variable not to be range MIN to MAX.
Algorithm::CP::IZ
Toshimitsu FUJIWARA, <tttfjw at gmail.com>
Copyright (C) 2015 by Toshimitsu FUJIWARA
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
To install Algorithm::CP::IZ, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::CP::IZ
CPAN shell
perl -MCPAN -e shell install Algorithm::CP::IZ
For more information on module installation, please visit the detailed CPAN module installation guide.