<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-X%3Allay008</id>
	<title>SE250:lab-X:llay008 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-X%3Allay008"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-X:llay008&amp;action=history"/>
	<updated>2026-04-28T16:04:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-X:llay008&amp;diff=9016&amp;oldid=prev</id>
		<title>Mark: 9 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-X:llay008&amp;diff=9016&amp;oldid=prev"/>
		<updated>2008-11-03T05:20:46Z</updated>

		<summary type="html">&lt;p&gt;9 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Lab X==&lt;br /&gt;
===Task One===&lt;br /&gt;
===Task Two===&lt;br /&gt;
This took a while to go through and figure out, partly because I didn&amp;#039;t know exactly what the OrderedStateList etc was doing.&lt;br /&gt;
Here is my attempt at a summary of the the search function...&lt;br /&gt;
&lt;br /&gt;
Takes in four arguments&lt;br /&gt;
* A State struct that represents the start state.&lt;br /&gt;
* A State struct that represents the end state.&lt;br /&gt;
* A pointer to StateList struct (called solution). &lt;br /&gt;
* A pointer to an int (called n_states_visited).&lt;br /&gt;
&lt;br /&gt;
Returns &lt;br /&gt;
* A boolean&lt;br /&gt;
&lt;br /&gt;
There are four initialised variables at the start:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  OrderedStateList open;&lt;br /&gt;
  StateSet visited;&lt;br /&gt;
  StateMap path_map;&lt;br /&gt;
  bool success = false;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The top three are then initialised by calling functions defined elsewhere  &lt;br /&gt;
While the OrderedStateList is not empty...&lt;br /&gt;
Get the next state&lt;br /&gt;
If it is the state that you are searching for...&lt;br /&gt;
success boolean is equal to true.&lt;br /&gt;
Break&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( ! is_empty_OrderedStateList( &amp;amp;open ) ) {&lt;br /&gt;
    State s;&lt;br /&gt;
    pop_OrderedStateList( &amp;amp;open, &amp;amp;s );&lt;br /&gt;
    if( same_state( &amp;amp;s, goal ) ) {&lt;br /&gt;
      success = true;&lt;br /&gt;
      break;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Else&lt;br /&gt;
Get the children of the state&lt;br /&gt;
Iterate through the children&lt;br /&gt;
if we have not seen the state...&lt;br /&gt;
put the state in the stateMap and add the state to the OrderedStateList&lt;br /&gt;
Release the children&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  } else {&lt;br /&gt;
      int i, n_children;&lt;br /&gt;
      State* cs = get_children( &amp;amp;s, &amp;amp;n_children );&lt;br /&gt;
      for( i = 0; i &amp;lt; n_children; i++ )&lt;br /&gt;
	if( add_to_StateSet( &amp;amp;visited, &amp;amp;cs[ i ] ) ) {&lt;br /&gt;
	  /* we have not yet seen this state */&lt;br /&gt;
	  put_StateMap( &amp;amp;path_map, &amp;amp;cs[ i ], &amp;amp;s );&lt;br /&gt;
	  add_to_OrderedStateList( &amp;amp;open, &amp;amp;cs[ i ] );&lt;br /&gt;
	}&lt;br /&gt;
      release_children( cs );&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create a new variable called s which is a State&lt;br /&gt;
Iterate through the states, goal state ? while the State is not equal to 0, going to the next state on the StateMap&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  { State* s;&lt;br /&gt;
  for( s = goal; s != 0; s = get_StateMap( &amp;amp;path_map, s ) )&lt;br /&gt;
    add_to_StateList( solution, s );&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If n_state_visited (this is the pointer to an int that is passed through in the function call), the pointer is now equal to the number of states visited(?)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  if( n_states_visited )&lt;br /&gt;
    *n_states_visited = visited.size;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
free the orderedStateList&lt;br /&gt;
free the StateSet&lt;br /&gt;
&lt;br /&gt;
return success&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  free_OrderedStateList( &amp;amp;open );&lt;br /&gt;
  free_StateSet( &amp;amp;visited );&lt;br /&gt;
&lt;br /&gt;
  return success;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Task Three===&lt;br /&gt;
===Task Four===&lt;br /&gt;
On of the problems that I had with this task was that it wouldn&amp;#039;t compile.  This was not helped by the fact that there was a mistake in the main function and the test example was for a 4*4 grid, instead of 3*3.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt of the result of trying to go from .12345678 to 12345678. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.12&lt;br /&gt;
345&lt;br /&gt;
678&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
1.2&lt;br /&gt;
345&lt;br /&gt;
678&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
142&lt;br /&gt;
3.5&lt;br /&gt;
678&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
142&lt;br /&gt;
.35&lt;br /&gt;
678&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
142&lt;br /&gt;
635&lt;br /&gt;
.78&lt;br /&gt;
 -&amp;gt;&lt;br /&gt;
142&lt;br /&gt;
635&lt;br /&gt;
7.8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&amp;lt;embed src=&amp;quot;http://i298.photobucket.com/albums/mm247/Phoenix100_album/Depth-first-search.jpg&amp;quot; width=1000 height=300&amp;gt;&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sadly, as is, my graph is not at all legible, though it can be read when you zoom in a couple hundred percent.  The node at the top of the graph is the final state and I can&amp;#039;t find the initial state... due to the fact that one side of my graph has been cut off. From this graph, the tree started at the right-hand corner.  The other nodes at the bottom of the tree are dead ends, where there are no new states that the tree can look at.&lt;br /&gt;
&lt;br /&gt;
Actually... couple/several hundred % zooming doesn&amp;#039;t exactly help because of the low pixel count. The tree just becomes a real big mess (blurr) to look at... [[User:Sbha077|State4Plasma]]&amp;lt;sup&amp;gt;[[User_talk:Sbha077|Talk]]&amp;lt;/sup&amp;gt; 15:13, 15 June 2008 (NZST)&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>