- 76 Views
- Uploaded on
- Presentation posted in: General

A Master-Slave Architecture to Integrate Sets and Finite Domains in Java

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Convegno Italiano di Logica Computazionale

A Master-Slave Architectureto Integrate Sets and Finite Domains in Java

F. Bergenti E. Panegai G. Rossi

Università degli Studi di Parma

Bari, 26-27 Giugno 2006

- Aims:
- Implement and validate the integration of JSetL (a set solver) and JFD (a finite domains solver);
- Find out a generic architecture approach for a cooperation between constraint solvers;

- The Master-Slave architecture;
- Case study: JSetL+JFD;
- Conclusions and future work.

- Solvers are normally implemented on the basis of more or less explicit tradeoffs between:
- Capabilities: the kinds of constraints they manage and under which assumptions; and
- Performances: the adopted strategies, heuristics and optimizations.

- Often single solvers cannot be used on hybrid problems. Idea: Combine several constraint solving techniques to solve problems that none of the single solvers can handle alone.

CILC 06 – Bari, 26/27 Giugno 2006

Meta-solver

Interface

Solver

1

Solver

2

Solver

n

- A common architectural outline can be found in many frameworks and architectures that explore the cooperative integration of constraint solvers:
- A top level of meta-resolution (namely a meta-solver);
- A set of constraint solvers; and
- An interface between the meta-solver and the object-level solvers.

CILC 06 – Bari, 26/27 Giugno 2006

Meta-solver

Interface

Solver

1

Solver

2

Solver

n

Solver

1

Interface

Solver

2

Solver

n

- We always need a layer of meta-resolution? Often this layer implies implementation efforts to realize functionalities already present in the solvers.
- The master-slave (M-S) approach:
No meta-solver

One of the solvers is opportunely selected and promoted to the role of master.

- The case study integrate two Java solvers, namely JSetL and JFD, into an added-value Java constraint solver capable of exploiting:
- The full expressive power of JSetL, with its inherent flexibility and generality; and
- The efficiency of JFD in treating finite integer domains variables.

- Constraint solving algorithms are basically the same exploited in CLP(Set+FD). Moving from a logic programming framework, to an OO programming context (Java) causes some implementation decisions to become more evident.

- The general architecture:
- Each solver is responsible for a predefined set of constraints and is equipped with a private constraint store (conjunction of atomic constraints).
- The main task of each solver is to try to reduce any conjunction of atomic constraints to a simplified (irreducible) form.
- One solver is selected as Master solver, all the others are Slaves (Slaves are black boxes).
- The master is in charge of distributing tasks to, and gathering results from, the slaves.
- The constraint distribution policy is based on a fixed a-priori mapping.

- Good selection of the master:
- The master should provide a constraint language that subsumes the union of the languages of all slaves;
- The performances: slaves should perform better than the master in their reference domains;
- The support for constraint programming abstractions, e.g., logical variables and nondeterminism;
- The possibility of extending the selected solver to integrate master-specific procedures (e.g., constraint dispatching, result processing etc.); and
- The public functionalities provided to programmers.

- At first stage the master needs to communicate constraints.
- Allocation of an atomic constraint C=op(t1,...,tn):
- (MASTER) If C is a constraint of the master and S=Ø, then the master solves it;
- (SLAVE) If C is not a constraint of the master and SØ, then C is posted to all slaves in S;
- (BOTH) If C is a constraint of the master and SØ, then the master posts C to all slaves in S and then solves it; or
- (UNKNOWN) If C is not a constraint of the master and S=Ø, the allocation fails, i.e., the constraint is unknown.

- Communication second stage: Interface that slave solvers provide:
- add(C)where C is a slave constraint to be added to the constraint store of the slave;
- get_constraints() that returns the conjunction of constraints that are present in the store of the slave;
- solve(B) where B is a value from an enumerative type used to specify which solving process is requested.

- Communication third stage: we need other glue functions for translate and filter constraints:
- master_to_slave(Slave,C)translates a master constraint C to the corresponding slave constraint;
- slave_to_master(Slave,D) translates a slave constraint D to the corresponding master constraint;
- which_type(C) that allows C to be classified as belonging to one of the four types of constraints MASTER, SLAVE, BOTH and UNKNOWN; and
- which_slave(C) that maps C to a possibly empty set of slaves that can handle it.

- The master's procedure for constraint solving:
procedure master_solve(Constraint Store)

repeat

reset(Store);

step(Store)

until is_final_form(Store)

end procedure;

- Actions are repeated until the solving process terminates successfully or until it fails.
- The process terminates successfully when no further constraint can be reduced or allocated to slaves and when all results are gathered from the constraint stores of slaves.
- The process fails when the master, or any slave, detects an inconsistency and no further nondeterministic choices are left open.

procedure step (Constraint Store)

C = extract(Store);// Constraint C

Selected_Slaves = Ø;

while C true do

T = which_type(C);

Slaves = which_slave(C);// Set Slaves

Selected_Slaves = Selected_Slaves υ Slaves;// Set Selected_Slaves

if T == SLAV E or T == BOTH then

for all Slave Slaves do

Slave.add(master_to_slave(Slave, C))

end for

if T == BOTH or T == MASTER then handle_constraint(Store,C)

C = extract(Store);

end while;

for all Slave Selected_Slaves do

Slave.solve(REDUCE);

slave_try_next(Slave, Store)

end for;

end procedure;

- The master and the slaves solvers can be sources of nondeterminism.
- The slaves interface modules further provide the following methods:
- next_solution() to explore the next nondeterministic alternative that a previous call to solve might have left open.
- save() that returns a snapshot of the current state of computation of a slave; and
- restore() that restores a previously saved state.

- Procedure used to explore nondeterministic choices left open by slaves:
procedure slave_try_next(Solver Slave, Constraint Store)

Constraint D;

either

D = slave_to_master(Slave, Slave.get_constraints());

if D == false then

fail

else

insert(Store,D);

end if;

orelse// try next nondeterministic alternative

Slave.next_solution();

slave_try_next(Slave, Store)

end either

end procedure;

- JSetL is a library that endows Java to support general purpose declarative programming. In particular, JSetL provides:
- logical variables,
- unification,
- list and set data structures,
- constraint solving, and
- nondeterminism.

procedure step (Constraint Store)

... // initialization

while C true do

T = which_type(C);

Slaves = which_slave(C);// Set Slaves

Selected_Slaves = Selected_Slaves υ Slaves;// Set Selected_Slaves

if T == SLAV E or T == BOTH then

for all Slave Slaves do

Slave.add(master_to_slave(Slave, C))

end for

if T == BOTH or T == MASTER then handle_constraint(Store,C)

C = extract(Store);

end while;

for all Slave Selected_Slaves do

Slave.solve(LABEL_ALL);

slave_try_next(Slave, Store)

end for;

end procedure;

- The handle_constraint procedure of JSetL+JFD:
procedure handle_constraint(Constraint Store, Constraint C)

if C == op (o1,o2) then

member(Store, C)

else if C == op=(o1,o2) then

equals(Store, C)

else if ... then

else if C == next then

slave_try_next(Store, C) // Unroll nondeterministic choice

end if

end procedure

- The procedure used to explore nondeterministic choices left open by slaves:
procedure slave_try_next(Constraint Store, Constraint C)

Constraint D;

if C.get_alternative() = 0 then

add_choice_point(next); // save computation state

D = slave_to_master(jfd, jfd.get constraints());

if D = false then

fail

else

insert(Store,D)

end if

else

jfd.next solution(); . try next nondeterministic alternative

insert(Store, next)

end if

end procedure

- Nondeterminism is confined to constraint solving:
procedure member(Constraint Store, Constraint C)

if C = op(o1,Ø) then

fail

else if C = op (o1,X) then

insert(Store, op=(X, {o1 |N}))

else if C = op (o1, {o2 | s}) then

if C.get_alternative() = 0 then

add_choice_point(C); // Save nondeterministic choice

insert(Store, op=(o1, o2))

else

insert(Store, op2(o1, s))

end if

else if ... then

end if

end procedure

- Extend constraints management and functionalities of JSetL+JFD.
- Tests on solving processand labeling.
- Tests with more slaves (i.e Solver for multisets).
- Application on Configuration Problems.
- Download at: http://www.math.unipr.it/~gianfr/JSetL/