# NAME

Algorithm::CP::IZ::Int - Domain variable for Algorithm::CP::IZ

# SYNOPSIS

``````  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";``````

# DESCRIPTION

Algorithm::CP::IZ::Int is perl representation of CSint object in iZ-C library. This class is called also 'domain variable'.

## DOMAIN

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}".``````

## FREE AND INSTANTIATED

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.

## FAIL

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.``````

# METHODS

stringify

Create string representation of this variable. ('""' operator has overloaded to call this method.)

keys

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";``
name

Get name of this variable.

name(NAME)

Set name of this variable.

nb_elements

Returns count of values in domain.

min

Returns minimum value of domain.

max

Returns maximum value of domain.

value

Returns instantiated value of this variable.

If this method called for not instancited variable, exception will be thrown.

is_free

Returns 1 (domain has more than 1 value) or 0 (domain has 1 only value).

is_instantiated

Returns 1 (instantiated, it means domain has only 1 value) or 0 (domain has more than 1 value).

domain

Returns array reference of domain values.

get_next_value(X)

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.

get_previous_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)

X is an integer value.

is_in(X)

Returns 1 (X is in domain) or 0 (X is not in domain)

X is an integer value.

Eq(X)

Constraints this variable "equal to X". X is an integer or an instance of Algorithm::CP::IZ::Int.

Neq(X)

Constraints this variable "not equal to X". X is an integer or an instance of Algorithm::CP::IZ::Int.

Le(X)

Constraints this variable "less or equal to X". X is an integer or an instance of Algorithm::CP::IZ::Int.

Lt(X)

Constraints this variable "less than X". X is an integer or instance of Algorithm::CP::IZ::Int.

Ge(X)

Constraints this variable "greater or equal to X". X is an integer or instance of Algorithm::CP::IZ::Int.

Gt(X)

Constraints this variable "greater than X". X is an integer or an instance of Algorithm::CP::IZ::Int.

InArray(ARRAYREF_OF_INT)

Constraints this variable to be element of arrayref.

NotInArray(ARRAYREF_OF_INT)

Constraints this variable not to be element of arrayref.

InInterval(MIN, MAX)

Constraints this variable to be range MIN to MAX.

NotInInterval(MIN, MAX)

Constraints this variable not to be range MIN to MAX.

# SEE ALSO

Algorithm::CP::IZ

# AUTHOR

Toshimitsu FUJIWARA, <tttfjw at gmail.com>

# COPYRIGHT AND LICENSE

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