## Problem Definition

There are two containers with capacities x and y. A well containing an inexhaustible supply of water is available.

A desired amount, z of water must be obtained in large container by

completely filling up container and/or emptying one container into another or onto the ground. Possible moves are:

* - filling the smaller jug from the water supply *

* - filling the larger jug from the water supply *

* - pouring out the contents of the smaller jug (onto the ground)*

* - pouring out the contents of the larger jug (onto the ground)*

* - pouring the contents of the smaller jug into the larger jug, until the larger jug is full, or the smaller jug is empty *

* - pouring the contents of the larger jug into the smaller jug, until the smaller jug is full, or the larger jug is empty *

This is two-jugs version, three-jugs version is also popular.

#### Idea

This problem has a naturally graph-like representation. State state can be easily implemented to CN. If we try to draw state space, elements will be like below;

*format of state : state (smallJug, largeJug).**initial state : (0, 0).**final state : (_, z). Any possible state that final jug value is z. (z is desired value for the problem)*

Every possible should be will be primitive, thus state can be change through these primitives.

## Solution Idea

This problem has a naturally graph-like representation. State state can be easily implemented to CN. If we try to draw state space, elements will be like below;

*format of state : state (smallJug, largeJug).**initial state : (0, 0).**final state : (_, z). Any possible state that final jug value is z. (z is desired value for the problem)*

Every possible move should be primitive, thus state can be change through these primitives.

## Global Variables

"State" is a record that contains small jug value, large jug value, move name in current state and cumulative cost up to current state.

"Item" is a record that has current state and a pointer to previous state. These "Item" s are pushed and popped to a stack in search process.

"ptr_item" is a pointer to "Item".

"path" is array of State. At the end of the search process full path copied to "path" from stack, then "path" is printed.

"cost" represents cost of the current state.

"smallJug" represents small jug value of the current state.

"largeJug" represents large jug value of the current state.

"stack_count" represents total elements in the stack.

"small_jug_cap" represents capacity of the small jug. It is defined by user at beginning of the program.

"large_jug_cap" represents capacity of the large jug. It is defined by user at beginning of the program.

"final_value" represents desired value in large jug at the end of the search process.

"current" is pointer to current item in the stack. It is used in search process.

"top" is pointer to top item of the stack.

## Subnets

Subnet: MainNetwork

Parameters:

Variables:

----------------------------------

## Primitives

"print" primitive copies stack content to "Path" array from end to beginning. Then it prints the "Path" content.

#### initialize

"initialize" primitive asks user for small jug capacity, large jug capacity, desired value of large jug and assigns them. It also assigns

initial values of other variables.

#### fillSmall

"fillSmall" primitive fills small jug, assigns cost and move for current state.

#### fillLarge

"fillLarge" primitive fills large jug, assigns cost and move for current state.

#### emptysmall

"emptySmall" primitive pours water in small jug to ground, assigns cost and move for current state.

#### emptyLarge

"emptyLarge" primitive pours water in large jug to ground, assigns cost and move for current state.

#### pourLargeToSmall

"pourLargeToSmall" primitive pours water in large jug to small jug until large jug empty or small jug is full

#### pourSmallToLarge

"pourSmallToLarge" primitive pours water in small jug to large jug until small jug empty or large jug is full

#### isFinal

"isFinal" primitive if checks current state is final state.

## OtherFunctions

#### onStack : boolean

"onStack" function returns true if reached state is in the stack.

#### isFound : boolean

"isFound" function returns true if reached state is desired state.

#### push

"push" procedure push an "Item" to stack.

#### pop

"pop" procedure pop an "Item" from stack.

#### SpiderSolutions : integer

"SpiderSolutions" function for CNP execution.