CS340    Project 2  -  The Chain Problem Part I

The chain problem consists of various lengths of chain that must be reconfigured into new arrangements. Operators can open one link and close one link. The initial state contains four chains, each with three links. The goal state consists of a single chain of 12 links in a circle. You want to fine the shortest solution to this problem.

I have set up this problem for you with the exception of the successors function in the file ChainProblem.java. You need to complete the successors function.

Recall that the successors function returns a list of StateActionPairs for a given state. In other words, for a given state you must determine which actions from that state will lead to other legal states. In the case of the chain problem the actions that can be taken are to open a link, close an already open link on a chain in either a loop or straight, and join two chains with an open link.

The state for this problem will be represented with the ChainState object. A ChainState contains an integer value for the number of open links and a Vector of Chain objects. So the initial state will have 0 open links and 4 Chain objects stored in the Vector. A Chain object contains an integer value specifying how many links are in the chain. It also has a boolean value which is true if the chain is linked into a loop, and false if the chain is straight. All four chains in the initial state will have 3 links and the loop value will be false.

We will simply represent the actions for this problem as String objects describing the actions.

You will need to create StateActionPair objects. The constructor for a StateActionPair has two arguments: the action and the state, in that order. The list of these objects will be maintained in a Vector. The Vector method addElement(Object obj) will add an element to the end of the list stored in the Vector. The successors function will return this Vector. To extract an element from a Vector, you can use the elementAt(int pos) method to extract the element at a given position. The first element in a Vector is always at position 0.

I have written some helper functions that you will want to use. The functions open, close, and join, take a state and return a modified state after the specified action is performed:

ChainState open(ChainState cs, int chainNum, int linkNum)

Returns the state resulting from opening a link linkNum in chain chainNum within the state cs.

ChainState close(ChainState cs, int chainNum, boolean loop)

Returns the state resulting from closing an open link on the chain chainNum. The boolean argument loop specifies whether the resulting chain will be in a loop or straight.

ChainState join(ChainState cs, int chainNum1, int chainNum2)

Returns the state resulting from joining the two specified chains.

Once you have written your code, you can add the chain problem to the AI program by modifying the file SearchPanel.java:

• Add a string "Chain Problem" to String[] ProblemStrings

• In the method createProblem, add an else if clause before the else like
else if (probName.equals("Chain Problem"))
problem = new ChainProblem();

When you run your search, the output of your problem will appear in the Java console window.

When you are satisfied with your code, submit your source code and also specify which search algorithm you used to find the optimal answer to the chain problem.