view release on metacpan or search on metacpan
}
#if (IZ_VERSION_MAJOR == 3 && IZ_VERSION_MINOR >= 6)
/* Helper functions for Algorithm::CP::IZ::ValueSelector::Simple */
/*
* Callback functions don't take class parameter therefore useer defined
* value selectors distincted by its index (when search function is called).
*/
typedef struct {
SV* init;
SV* next;
SV* end;
} vsSimple;
static vsSimple* vsSimpleArray = NULL;
static size_t vsSimpleArraySize = 0;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal((SV*)newRV(ext)));
XPUSHs(sv_2mortal((SV*)newSViv(depth)));
XPUSHs(sv_2mortal((SV*)newSViv(index)));
XPUSHs(sv_2mortal((SV*)newSViv(vs->method)));
XPUSHs(sv_2mortal((SV*)newSViv(vs->value)));
PUTBACK;
call_method("before_value_selection", G_DISCARD);
FREETMPS;
LEAVE;
}
static void searchNotify_AfterValueSelection(IZBOOL result, int depth, int index, const CSvalueSelection* vs, CSint** allvars, int nbVars, void* ext) {
dTHX;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal((SV*)newRV(ext)));
XPUSHs(sv_2mortal((SV*)newSViv(result)));
XPUSHs(sv_2mortal((SV*)newSViv(depth)));
XPUSHs(sv_2mortal((SV*)newSViv(index)));
XPUSHs(sv_2mortal((SV*)newSViv(vs->method)));
XPUSHs(sv_2mortal((SV*)newSViv(vs->value)));
PUTBACK;
call_method("after_value_selection", G_DISCARD);
FREETMPS;
LEAVE;
}
static void searchNotify_Enter(int depth, int index, CSint** allvars, int nbVars, void* ext) {
dTHX;
dSP;
ENTER;
else
Newx(ext, 1, int);
if (ext) {
cs_initValueSelector(vs, index, array, size, ext);
}
RETVAL = ext;
OUTPUT:
RETVAL
void
cs_selectNextValue(vs, index, array, size, ext)
void* vs
int index
void* array
int size
void* ext
PREINIT:
CSvalueSelection r;
int rc;
PPCODE:
rc = cs_selectNextValue(&r, vs, index, array, size, ext);
if (rc) {
XPUSHs(sv_2mortal(newSViv(r.method)));
XPUSHs(sv_2mortal(newSViv(r.value)));
}
int
cs_endValueSelector(vs, index, array, size, ext)
void* vs
int index
void* array
max_fail,
INT2PTR(CSnoGoodSet*, SvIV(ngs)),
(nf_ref ? INT2PTR(CSsearchNotify*, SvIV(nf_ref)) : NULL));
Safefree(array);
Safefree(vs_array);
OUTPUT:
RETVAL
int
cs_selectValue(rv, method, value)
SV *rv
int method
int value
PREINIT:
CSvalueSelection vs;
CODE:
vs.method = method;
vs.value = value;
RETVAL = cs_selectValue(INT2PTR(CSint*, SvIV(SvRV(rv))), &vs);
OUTPUT:
RETVAL
void*
cs_createSearchNotify(obj)
SV* obj
CODE:
RETVAL = cs_createSearchNotify(SvRV(obj));
OUTPUT:
RETVAL
searchNotify_searchStart);
void
searchNotify_set_search_end(notify)
SV* notify
CODE:
cs_searchNotifySetSearchEnd(INT2PTR(void*, SvIV(notify)),
searchNotify_searchEnd);
void
searchNotify_set_before_value_selection(notify)
SV* notify
CODE:
cs_searchNotifySetBeforeValueSelection(INT2PTR(void*, SvIV(notify)),
searchNotify_BeforeValueSelection);
void
searchNotify_set_after_value_selection(notify)
SV* notify
CODE:
cs_searchNotifySetAfterValueSelection(INT2PTR(void*, SvIV(notify)),
searchNotify_AfterValueSelection);
void
searchNotify_set_enter(notify)
SV* notify
CODE:
cs_searchNotifySetEnter(INT2PTR(void*, SvIV(notify)),
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use Algorithm::CP::IZ ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'value_selector' => [ qw(
CS_VALUE_SELECTOR_MIN_TO_MAX
CS_VALUE_SELECTOR_MAX_TO_MIN
CS_VALUE_SELECTOR_LOWER_AND_UPPER
CS_VALUE_SELECTOR_UPPER_AND_LOWER
CS_VALUE_SELECTOR_MEDIAN_AND_REST
CS_VALUE_SELECTION_EQ
CS_VALUE_SELECTION_NEQ
CS_VALUE_SELECTION_LE
CS_VALUE_SELECTION_LT
CS_VALUE_SELECTION_GE
CS_VALUE_SELECTION_GT
) ]);
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'value_selector'} } );
our $VERSION = '0.07';
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function.
my $constname;
our $AUTOLOAD;
($constname = $AUTOLOAD) =~ s/.*:://;
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
my $params = shift;
validate([$var_array, $params], ["vA0", sub {_validate_search_params($var_array, @_)}],
"Usage: search([variables], {key=>value,...}");
my $array = [map { $$_ } @$var_array];
my $max_fail = -1;
my $find_free_var_id = 0;
my $find_free_var_func = sub { die "search: Internal error"; };
my $criteria_func;
my $value_selectors;
my $max_fail_func;
my $ngs;
my $notify;
if ($params->{FindFreeVar}) {
my $ffv = $params->{FindFreeVar};
if (ref $ffv) {
$find_free_var_id = -1;
$find_free_var_func = sub {
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
if ($params->{Criteria}) {
$criteria_func = $params->{Criteria};
}
if ($params->{MaxFail}) {
$max_fail = int($params->{MaxFail});
}
if ($params->{ValueSelectors}) {
$value_selectors = $params->{ValueSelectors};
}
if ($params->{MaxFailFunc}) {
$max_fail_func = $params->{MaxFailFunc};
}
if ($params->{NoGoodSet}) {
$ngs = $params->{NoGoodSet};
}
if ($params->{Notify}) {
$notify = $params->{Notify};
unless (ref $notify eq 'Algorithm::CP::IZ::SearchNotify') {
$notify = Algorithm::CP::IZ::SearchNotify->new($notify);
}
$notify->set_var_array($var_array);
}
my $is_search35 = $value_selectors || $max_fail_func || $ngs || $notify;
if ($is_search35) {
unless ($value_selectors) {
if ($criteria_func) {
$Algorithm::CP::IZ::CriteriaValueSelector::CriteriaFunction = $criteria_func;
$value_selectors = [
map {
$self->create_value_selector_simple("Algorithm::CP::IZ::CriteriaValueSelector")
} (0..scalar(@$var_array)-1)];
}
else {
$value_selectors = [
map {
$self->get_value_selector(&CS_VALUE_SELECTOR_MIN_TO_MAX)
} (0..scalar(@$var_array)-1)];
}
}
my $i = 0;
for my $v (@$array) {
my $vs = $value_selectors->[$i];
$vs->prepare($i);
$i++;
}
if ($max_fail_func) {
return Algorithm::CP::IZ::cs_searchValueSelectorRestartNG(
$array,
$value_selectors,
$find_free_var_id,
$find_free_var_func,
$max_fail_func,
$max_fail,
defined($ngs) ? $ngs->{_ngs} : 0,
defined($notify) ? $notify->{_ptr} : 0);
}
else {
return Algorithm::CP::IZ::cs_searchValueSelectorFail(
$array,
$value_selectors,
$find_free_var_id,
$find_free_var_func,
$max_fail,
defined($notify) ? $notify->{_ptr} : 0);
}
}
else {
if ($criteria_func) {
return Algorithm::CP::IZ::cs_searchCriteria($array,
$find_free_var_id,
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
return sprintf("%d.%d.%d",
$major,
$self->IZ_VERSION_MINOR,
$self->IZ_VERSION_PATCH);
}
# not supported
return;
}
sub get_value_selector {
my $self = shift;
my $id = shift;
return Algorithm::CP::IZ::ValueSelector::IZ->new($self, $id);
}
sub create_value_selector_simple {
my $self = shift;
my $id = shift;
return Algorithm::CP::IZ::ValueSelector::Simple->new($self, $id);
}
sub create_no_good_set {
my $self = shift;
my ($var_array, $prefilter, $max_no_good, $ext) = @_;
$max_no_good ||= 0;
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
=item search(VARIABLES [, PARAMS])
Try to instantiate all VARIABLES(arrayref).
PARAMS will be hashref containning following keys.
=over 2
=item FindFreeVar
FindFreeVar specifies variable selection strategy.
Choose constants from Algorithm::CP::IZ::FindFreeVar or specify your own
function as coderef here.
Most simple function will be following. (select from first)
sub simple_find_free_var{
my $array = shift; # VARIABLES is in parameter
my $n = scalar @$array;
for my $i (0..$n-1) {
return $i if ($array->[$i]->is_free);
}
return -1; # no free variable
};
=item Criteria
Criteria specifies value selection strategy.
Specify your own function as coderef here.
sub sample_criteria {
# position in VARIABLES, and candidate value
my ($index, $val) = @_;
# first value used in search is
# minimum value returned by criteria.
return $val;
};
(If ValueSelector is specified, this parameter is ignored.)
=item MaxFail
Upper limit of fail count while searching solutions.
=item ValueSelectors
Arrayref of Algorithm::CP::IZ::ValueSelector instances created via
get_value_selector or create_value_selector_simple method.
(If ValueSelector is specified, this parameter is ignored.)
=item MaxFailFunc
CodeRef of subroutine which returns maxfail for restart.
=item NoGoodSet
A Algorithm::CP::IZ::NoGoodSet instance which collects NoGoods.
=item Notify
Specify a notify object receives following notification by search function.
search_start
search_end
before_value_selection
after_value_selection
enter
leave
found
if OBJECT is a object, method having notification name will be called.
if OBJECT is a hashref, notification name must be a key of hash and
value must be a coderef.
=back
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
}
EXTRA is a just a data passed to callbeck as parameter (it can be anything).
=item get_version
Returns version string like "3.5.0".
undef will be returned if getVersion() is not supported in iZ-C (old version).
=item get_value_selector(ID)
Get built-in value selector (instance of Algorithm::CP::IZ::ValueSelector) specifed by ID.
ID must be selected from following constants defined in package Algorithm::CP::IZ.
=over
=item CS_VALUE_SELECTOR_MIN_TO_MAX
=item CS_VALUE_SELECTOR_MAX_TO_MIN
=item CS_VALUE_SELECTOR_LOWER_AND_UPPER
=item CS_VALUE_SELECTOR_UPPER_AND_LOWER
=item CS_VALUE_SELECTOR_MEDIAN_AND_REST
=back
(These values are exported by Algorithm::CP::IZ and can be imported using tag 'value_selector')
Returned object will be used as a parameter ValueSelectors when calling "search" method.
use Algorithm::CP::IZ qw(:value_selector);
my $vs = $iz->get_value_selector(CS_VALUE_SELECTOR_MIN_TO_MAX);
my $v1 = $iz->create_int(1, 9);
my $v2 = $iz->create_int(1, 9);
$iz->Add($v1, $v2)->Eq(12);
my $rc = $iz->search([$v1, $v2], {
ValueSelectors => [ $vs, $vs ],
});
=item create_value_selector_simple(CLASS_NAME)
Create user defined value-seelctor defined by class named CLASS_NAME.
This class must have constructor named "new" and method namaed "next".
use Algorithm::CP::IZ qw(:value_selector);
package VSSample1;
sub new {
my $class = shift;
my ($v, $index) = @_;
my $self = {
_pos => 0,
};
bless $self, $class;
lib/Algorithm/CP/IZ.pm view on Meta::CPAN
my @ret = (CS_VALUE_SELECTION_EQ, $domain->[$pos]);
$self->{_pos} = ++$pos;
# return pair of (CS_VALUE_SELECTION_*, value)
return @ret;
}
my $v1 = $iz->create_int(1, 9);
my $v2 = $iz->create_int(1, 9);
$iz->Add($v1, $v2)->Eq(12);
my $vs = $iz->create_value_selector_simple("VSSample1");
my $rc = $iz->search([$v1, $v2], {
ValueSelectors => [ $vs, $vs ],
});
=item create_no_good_set(VARIABLES, PRE_FILTER, MAX_NO_GOOD, EXT)
Create an instance of Algorithm::CP::IZ::NoGoodSet. Returned object will be used as a
parameter NoGoodSet when calling "search" method.
=back
lib/Algorithm/CP/IZ/Int.pm view on Meta::CPAN
return Algorithm::CP::IZ::cs_NotInInterval($$self, int($min), int($max));
}
sub _invalidate {
my $self = shift;
bless $self, __PACKAGE__ . "::InvalidInt";
}
sub select_value {
my $self = shift;
my ($method, $value) = @_;
validate([$method, $value], ["I", "I"],
"Usage: selectValue(method, value)");
return Algorithm::CP::IZ::cs_selectValue($self, $method, $value);
}
sub DESTROY {
my $self = shift;
}
1;
__END__
lib/Algorithm/CP/IZ/SearchNotify.pm view on Meta::CPAN
package Algorithm::CP::IZ::SearchNotify;
use strict;
use warnings;
use Carp qw(croak);
my @method_names = qw(
search_start
search_end
before_value_selection
after_value_selection
enter
leave
found
);
sub new {
my $class = shift;
my $obj = shift;
my $self = {
lib/Algorithm/CP/IZ/SearchNotify.pm view on Meta::CPAN
&{$self->{_methods}->{search_start}}($max_fails, $self->{_var_array});
}
sub search_end {
my $self = shift;
my ($result, $nb_fails, $max_fails) = @_;
&{$self->{_methods}->{search_end}}($result, $nb_fails, $max_fails, $self->{_var_array});
}
sub before_value_selection {
my $self = shift;
my ($depth, $index, $method, $value) = @_;
&{$self->{_methods}->{before_value_selection}}($depth, $index, [$method, $value], $self->{_var_array});
}
sub after_value_selection {
my $self = shift;
my ($result, $depth, $index, $method, $value) = @_;
&{$self->{_methods}->{after_value_selection}}($result, $depth, $index, [$method, $value], $self->{_var_array});
}
sub enter {
my $self = shift;
my ($depth, $index) = @_;
&{$self->{_methods}->{enter}}($depth, $index, $self->{_var_array});
}
sub leave {
lib/Algorithm/CP/IZ/ValueSelector.pm view on Meta::CPAN
sub next {
my $self = shift;
my $vs = $self->{_vs};
my $index = $self->{_index};
my $array = $self->{_array};
my $ptr = $self->{_ptr};
my $size = $self->{_size};
return Algorithm::CP::IZ::cs_selectNextValue($vs, $index, $$array, $size, $ptr);
}
# end is bound to DESTORY in Perl way
sub DESTROY {
my $self = shift;
my $vs = $self->{_vs};
my $index = $self->{_index};
my $array = $self->{_array};
my $ptr = $self->{_ptr};
lib/Algorithm/CP/IZ/ValueSelector.pm view on Meta::CPAN
}
#
# ValueSelector user defined (simple)
#
# init : $cls->new(Int_instance) is called. Instance of $cls must be returned.
# next : $obj->next(Int_instane) is called.
# end : $obj is released.
#
# Callback functions don't take class parameter therefore useer defined
# value selectors distincted by its index (when search function is called).
#
package Algorithm::CP::IZ::ValueSelector::Simple;
use base qw(Algorithm::CP::IZ::ValueSelector);
sub new {
my $class = shift;
my ($iz, $cls) = @_;
my $vs = Algorithm::CP::IZ::createSimpleValueSelector();
is("$i", "3");
}
SKIP: {
skip "old iZ", 4
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $v = $iz->create_int(0, 10);
ok($v->select_value(&Algorithm::CP::IZ::CS_VALUE_SELECTION_GE, 4));
is($v->min, 4);
is($v->max, 10);
ok(!$v->select_value(&Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ, 1));
}
# memory leak
SKIP: {
eval "use Test::LeakTrace";
my $leak_test_enabled = !$@;
skip "Test::LeakTrace is not installed", 1
unless ($leak_test_enabled);
my $v = $iz->create_int(0, 1);
t/02search.t view on Meta::CPAN
skip "old iZ", 6
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $v1 = $iz->create_int(0, 10);
my $v2 = $iz->create_int(0, 5);
$iz->AllNeq([$v1, $v2]);
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
my $label = $iz->save_context();
my $rc = $iz->search([$v1, $v2],
{ ValueSelectors
=> [$vs, $vs], }
);
is($rc, 1);
is($v1->value, 0);
is($v2->value, 1);
$iz->restore_context_until($label);
$vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MAX_TO_MIN);
$rc = $iz->search([$v1, $v2],
{ ValueSelectors => [$vs, $vs], }
);
is($rc, 1);
is($v1->value, 10);
is($v2->value, 5);
}
# test MaxFail uinsg send more money
t/02search.t view on Meta::CPAN
$iz->AllNeq([$s, $e, $n, $d, $m, $o, $r, $y]);
my $v1 = $iz->ScalProd([$s, $e, $n, $d], [1000, 100, 10, 1]);
my $v2 = $iz->ScalProd([$m, $o, $r, $e], [1000, 100, 10, 1]);
my $v3 = $iz->ScalProd([$m, $o, $n, $e, $y], [10000, 1000, 100, 10, 1]);
my $v4 = $iz->Add($v1, $v2);
$v3->Eq($v4);
my $func_called = 0;
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
my $restart = 0;
# cannot solve by MaxFail
$iz->save_context;
my $rc1 = $iz->search([$s, $e, $n, $d, $m, $o, $r, $y],
{
ValueSelectors =>
[map { $vs } 1..8],
MaxFail => 1,
t/02search.t view on Meta::CPAN
$iz->AllNeq([$s, $e, $n, $d, $m, $o, $r, $y]);
my $v1 = $iz->ScalProd([$s, $e, $n, $d], [1000, 100, 10, 1]);
my $v2 = $iz->ScalProd([$m, $o, $r, $e], [1000, 100, 10, 1]);
my $v3 = $iz->ScalProd([$m, $o, $n, $e, $y], [10000, 1000, 100, 10, 1]);
my $v4 = $iz->Add($v1, $v2);
$v3->Eq($v4);
my $func_called = 0;
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
my $array = [$s, $e, $n, $d, $m, $o, $r, $y];
my $ngs = $iz->create_no_good_set($array, undef, 100, undef);
my $restart = 0;
my $rc = $iz->search($array,
{
ValueSelectors => [map { $vs } 1..8],
MaxFailFunc => sub {
$func_called++;
return ++$restart;
t/02search.t view on Meta::CPAN
$iz->cancel_search;
ok(1);
}
# FindFreeVar error
{
my $iz = Algorithm::CP::IZ->new();
my $rc = -1234;
my $v = $iz->create_int(0, 9);
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
my $label = $iz->save_context;
# nothing returned
eval {
$rc = $iz->search([$v],
{
FindFreeVar => sub {
return;
},
t/02search.t view on Meta::CPAN
SKIP: {
my $iz = Algorithm::CP::IZ->new();
skip "old iZ", 1
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $rc = -1234;
my $v = $iz->create_int(0, 9);
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
my $label = $iz->save_context;
# nothing returned
eval {
$rc = $iz->search([$v],
{
ValueSelectors => [$vs],
MaxFailFunc => sub {
return;
t/02search.t view on Meta::CPAN
# MaxFailFunc only
SKIP: {
my $iz = Algorithm::CP::IZ->new();
skip "old iZ", 1
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $v = $iz->create_int(0, 9);
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
my $rc = $iz->search([$v],
{
MaxFailFunc => sub {
return 1;
}
});
is($rc, 1);
is($v->value, 0);
}
use strict;
use warnings;
use Test::More tests => 41;
BEGIN { use_ok('Algorithm::CP::IZ') };
BEGIN { use_ok('Algorithm::CP::IZ::ValueSelector') };
use Algorithm::CP::IZ qw(:value_selector);
SKIP: {
my $iz = Algorithm::CP::IZ->new;
skip "old iZ", 7
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $v = $iz->create_int(0, 2);
my $vs = $iz->get_value_selector(CS_VALUE_SELECTOR_MIN_TO_MAX);
my $vsi = $vs->init(0, [$v]);
my ($meth, $val);
($meth, $val) = $vsi->next; # 0
is($meth, Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ);
is($val, 0);
($meth, $val) = $vsi->next; # 1
is($meth, Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ);
SKIP: {
my $iz = Algorithm::CP::IZ->new;
skip "old iZ", 14
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $v = $iz->create_int(0, 2);
my $vs = $iz->get_value_selector(CS_VALUE_SELECTOR_MAX_TO_MIN);
my $vsi = $vs->init(0, [$v]);
my ($meth, $val);
($meth, $val) = $vsi->next; # 2
is($meth, Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ);
is($val, 2);
($meth, $val) = $vsi->next; # 1
is($meth, Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ);
}
SKIP: {
my $iz = Algorithm::CP::IZ->new;
skip "old iZ", 0
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $obj = $iz->create_value_selector_simple("TestVS1");
my $v = $iz->create_int(0, 2);
# my $vsi = $obj->init(0, [$v]);
# print $vsi->next;
$iz = undef;
}
SKIP: {
my $iz = Algorithm::CP::IZ->new();
skip "old iZ", 13
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $vs = $iz->create_value_selector_simple("TestVS1");
my $v1 = $iz->create_int(-2, 1);
my $v2 = $iz->create_int(3);
my $vs1 = $vs->init(0, [$v1, $v2]);
my ($meth, $val);
($meth, $val) = $vs1->next;
is($meth, Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ);
is($val, -2);
($meth, $val) = $vs1->next;
is($meth, Algorithm::CP::IZ::CS_VALUE_SELECTION_EQ);
skip "old iZ", 3
unless (defined($iz->get_version)
&& $iz->IZ_VERSION_MAJOR >= 3
&& $iz->IZ_VERSION_MINOR >= 6);
my $v1 = $iz->create_int(0, 10);
my $v2 = $iz->create_int(0, 5);
$iz->AllNeq([$v1, $v2]);
my $vs = $iz->create_value_selector_simple("TestVS1");
my $label = $iz->save_context();
my $rc = $iz->search([$v1, $v2],
{ ValueSelectors
=> [$vs, $vs], }
);
is($rc, 1);
is($v1->value, 0);
is($v2->value, 1);
}
return @ret;
}
sub DESTROY {
}
package main;
my $v1 = $iz->create_int(0, 10);
my $v2 = $iz->create_int(0, 5);
my $vs = $iz->create_value_selector_simple("TestVS");
eval {
my $rc = $iz->search([$v1, $v2],
{ ValueSelectors
=> [$vs, $vs], }
);
};
# error
ok($@);
return @ret;
}
sub DESTROY {
}
package main;
my $v1 = $iz->create_int(0, 10);
my $v2 = $iz->create_int(0, 5);
my $vs = $iz->create_value_selector_simple("TestVS");
eval {
my $rc = $iz->search([$v1, $v2],
{ ValueSelectors
=> [$vs, $vs], }
);
};
# error
ok($@);
$iz->AllNeq([$s, $e, $n, $d, $m, $o, $r, $y]);
my $v1 = $iz->ScalProd([$s, $e, $n, $d], [1000, 100, 10, 1]);
my $v2 = $iz->ScalProd([$m, $o, $r, $e], [1000, 100, 10, 1]);
my $v3 = $iz->ScalProd([$m, $o, $n, $e, $y], [10000, 1000, 100, 10, 1]);
my $v4 = $iz->Add($v1, $v2);
$v3->Eq($v4);
my $func_called = 0;
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_LOWER_AND_UPPER);
my $array = [$y, $s, $e, $n, $d, $m, $o, $r];
my @ng_set;
package TestNG;
sub new {
my $class = shift;
bless {}, $class;
}
# apply NoGood over current solution must fail
my $nOk = 0;
for my $ng (@ng_set) {
my $label = $iz->save_context;
my $is_fail;
for my $nge (@$ng) {
print "$nge\n";
my $v = $array->[$nge->index];
if (!$v->select_value($nge->method, $nge->value)) {
$is_fail = 1;
last;
}
}
$iz->restore_context_until($label);
$nOk++ if ($is_fail);
}
is($nOk, scalar(@ng_set));
}
$iz->AllNeq([$s, $e, $n, $d, $m, $o, $r, $y]);
my $v1 = $iz->ScalProd([$s, $e, $n, $d], [1000, 100, 10, 1]);
my $v2 = $iz->ScalProd([$m, $o, $r, $e], [1000, 100, 10, 1]);
my $v3 = $iz->ScalProd([$m, $o, $n, $e, $y], [10000, 1000, 100, 10, 1]);
my $v4 = $iz->Add($v1, $v2);
$v3->Eq($v4);
my $func_called = 0;
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_LOWER_AND_UPPER);
my $array = [$y, $s, $e, $n, $d, $m, $o, $r];
my @ng_set;
package TestNG2;
sub new {
my $class = shift;
bless {}, $class;
}
t/09notify.t view on Meta::CPAN
my $array = shift;
$called{search_end}++;
# 9567 + 1085 = 10652
# SEND MORE MONEY
# 95671082
$called{search_end_solution} = join("", ($s, $e, $n, $d, $m, $o, $r, $y));
}
sub before_value_selection {
my $self = shift;
my ($depth, $index, $vs, $array) = @_;
# debug
# print STDERR "value selection: $depth, $index, $array\n";
# print STDERR " ", $vs->[0], ", ", $vs->[1], "\n";
# print STDERR join(", ", map {$_->min} @$array), "\n";
}
sub after_value_selection {
my $self = shift;
my ($result, $depth, $index, $vs, $array) = @_;
# debug
# print STDERR "after value selection: $result, $depth, $index, $array\n";
# print STDERR " ", $vs->[0], ", ", $vs->[1], "\n";
# print STDERR join(", ", map {$_->min} @$array), "\n";
}
sub enter {
my $self = shift;
my ($depth, $index, $array) = @_;
# debug
# print STDERR "enter: $depth, $index, $array\n";
# print STDERR join(", ", map {"$_"} @$array), "\n";
t/09notify.t view on Meta::CPAN
# debug
# print STDERR "found: $depth, $array\n";
# print STDERR join(", ", map {"$_"} @$array), "\n";
return 1;
}
package main;
my $obj = TestObj->new;
my $sn = $iz->create_search_notify($obj);
# print STDERR "perl obj = $obj, sn = $sn\n";
my $vs = $iz->get_value_selector(&Algorithm::CP::IZ::CS_VALUE_SELECTOR_MIN_TO_MAX);
$iz->save_context;
my $rc1 = $iz->search([$d, $e, $n, $y, $m, $o, $r, $s],
{
ValueSelectors =>
[map { $vs } 1..8],
MaxFail => 100,
Notify => $sn,
});
is($rc1, 1);