<?xml version="1.0" encoding="iso-8859-1"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>CS 312, section 003</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/" />
<modified>2005-04-13T21:51:55Z</modified>
<tagline>Algorithm Analysis, MWF 4-450pm, 120 TMCB, Jones M.</tagline>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5</id>
<generator url="http://www.movabletype.org/" version="3.11">Movable Type</generator>
<copyright>Copyright (c) 2005, jones</copyright>
<entry>
<title>Final Exam Format</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/04/final_exam_form.html" />
<modified>2005-04-13T21:51:55Z</modified>
<issued>2005-04-13T21:51:55Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.764</id>
<created>2005-04-13T21:51:55Z</created>
<summary type="text/plain">Its a two part exam. The first part has 15 fill-in-the-bubble questions. The second part has 5 short essay answer type questions. There are no point values listed on the exam. The first 15 questions are worth 2 points each....</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Exams</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>Its a two part exam.  The first part has 15 fill-in-the-bubble questions.  The second part has 5 short essay answer type questions.  There are no point values listed on the exam.  The first 15 questions are worth 2 points each.  The second set of 5 questions are worth 12 points each.  So that's 30 points on the fill-in-the-bubble and 60 points on the essay type questions.  </p>]]>
<![CDATA[<p>If I were studying for the exam, I would be sure I knew... <br />
<ul> <br />
<li> How to solve recurrence relations<br />
<li> How to do linear programming and what slack form looks like<br />
<li> How to design algorithms and what the tradeoffs are between the different classes of algorithms we studied. <br />
<li> How the graph-based algorithms we studied work. <br />
<li> The stuff on the study lists for the other exams. <br />
</ul><br />
 </p>]]>
</content>
</entry>
<entry>
<title>Important typo on the final exam</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/04/important_typo_1.html" />
<modified>2005-04-13T21:47:59Z</modified>
<issued>2005-04-13T21:47:59Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.763</id>
<created>2005-04-13T21:47:59Z</created>
<summary type="text/plain">On the final exam, the question that asks you to put a linear programming problem into &quot;basic form&quot; should read &quot;slack form&quot; (Its problem 18)...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Exams</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>On the final exam, the question that asks you to put a linear programming problem into "basic form" should read "slack form"  (Its problem 18)</p>]]>

</content>
</entry>
<entry>
<title>Linear programming problem (due 4/13)</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/04/linear_programm.html" />
<modified>2005-04-04T17:30:28Z</modified>
<issued>2005-04-04T17:29:36Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.756</id>
<created>2005-04-04T17:29:36Z</created>
<summary type="text/plain">Here is the problem to solve with your linear programming project. The project is due the last day of classes. There will be no late days. The project is to turn this problem into a linear programming problem and then...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Projects</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[Here is the problem to solve with your linear programming project.   The project is due the last day of classes.  <b>There will be no late days</b>.  The project is to turn this problem into a linear programming problem and then solve it with your simplex solver.  You are free to use any input format you like and you are free to just hard-code the input right into your program if you like.  This is the only problem your program will be tested on (but we will look at your source code to make sure your program isn't just "wait 2 seconds then return the solution").  <p>

You are the operations director for a processing plant at a large
mine.  Your job is to devise a program, or plan, for the plant that
maximizes profits while staying within the resource budget.  The plant
produces four major resources: copper, gold, silver and platinum.  <p>

In a given week, the mine produces 2,000 tons of ore that must be
processed into some combination of the four major resources.  A ton of
ore contains 10 ounces of copper, 2 ounces of gold, 3 ounces of silver
and 1 ounce of platinum. You many only extract one resource from each
unit of ore processed.<p>

Processing the ore requires power, water, labor and use of one of the
three processing lines.  Producing each of the resources requires
different amounts of processing resources.  One ounce of copper
requires 30 kW hours, 1,000 gallons of water, 50 hours of labor and 4
hours of processing time on a processing line.  One ounce of gold
requires 15 kW hours, 6,000 gallons of water, 20 hours of labor and 6
hours of processing time on a processing line.  One ounce of silver
requires 19 kW hours, 4,100 gallons of water, 21 hours of labor and 19
hours of processing time on a processing line.  One ounce of platinum
requires 12 kW hours, 9,100 gallons of water, 10 hours of labor and 30
hours of processing time on a processing line.<p>

There is only a limited amount of power, water, labor and processsing
line time available.  In a given week, you may use 1,000 kW hours of
power, 1,000,000 gallons of water, 640 hours of laber and you can run
the processing lines 24 hours a day for 7 days a week for a total of
504 hours.<p>

Finally, each ounce of finished resource has an associated profit.  An
ounce of copper is worth $10.20, an ounce of gold is worth $422.30
dollars, an ounce of silver is worth $6.91 and an ounce of platinum is
worth $853.00.<p>  ]]>

</content>
</entry>
<entry>
<title>TSP is due today, Monday 4/4</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/04/tsp_is_due_toda.html" />
<modified>2005-04-04T15:41:13Z</modified>
<issued>2005-04-04T15:41:13Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.755</id>
<created>2005-04-04T15:41:13Z</created>
<summary type="text/plain">Just a reminder that the due date for the TSP project was moved to today. Be sure to turn something in (not neccesarily today) even if it is incomplete....</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Projects</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>Just a reminder that the due date for the TSP project was moved to today.  Be sure to turn something in (not neccesarily today) even if it is incomplete. </p>]]>

</content>
</entry>
<entry>
<title>Notes on linear programming (updated 4/4)</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/04/notes_on_linear.html" />
<modified>2005-04-04T22:05:29Z</modified>
<issued>2005-04-04T12:23:19Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.750</id>
<created>2005-04-04T12:23:19Z</created>
<summary type="text/plain">The notes were updated to include implementation notes on page 10 on 4/4. We have developed a set of notes on linear programming. The notes are complete, although I wouldn&apos;t be surprised if they were expanded as we cover them...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Lectures</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>The notes were updated to include implementation notes on page 10 on 4/4. </p>

<p>We have developed a set of notes on <a href="http://vv.cs.byu.edu/~jones/cs312/linear-programming.pdf"> linear programming</a>.  The notes are complete, although I wouldn't be surprised if they were expanded as we cover them in class.  The latest version will always be available here. </p>

<p>We will cover this material in class a little on Wednesday, all day Friday and Monday.   The last project is to code up simplex and solve a little optimization problem. </p>]]>

</content>
</entry>
<entry>
<title>More resources for learning linear programming</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/04/more_resources.html" />
<modified>2005-04-01T22:22:13Z</modified>
<issued>2005-04-01T22:22:13Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.753</id>
<created>2005-04-01T22:22:13Z</created>
<summary type="text/plain">[a LP flash tutorial, notes on linear programming] The flash tutorial is quite nice, copmlete and slow. The notes are from Sean Warnick. They are also quite good....</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Lectures</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>[a <a title="LP" href="http://commerce.concordia.ca/bourjolly/lp.html">LP flash tutorial</a>, <a href="http://vv.cs.byu.edu/~jones/cs312/l33-linear-prog.pdf">notes on linear programming</a>] The flash tutorial is quite nice, copmlete and slow.  The notes are from Sean Warnick.  They are also quite good.  <br />
</p>]]>

</content>
</entry>
<entry>
<title>Solutions posted</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/solutions_poste.html" />
<modified>2005-03-31T15:53:42Z</modified>
<issued>2005-03-31T15:53:08Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.752</id>
<created>2005-03-31T15:53:08Z</created>
<summary type="text/plain">The solutions to the TSP premature cycle detection and edge inclusion/exclusion homeworks have been posted....</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Homework</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>The solutions to the TSP premature cycle detection and edge inclusion/exclusion homeworks have been posted. </p>]]>

</content>
</entry>
<entry>
<title>Scheduling for presentations</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/scheduling_for.html" />
<modified>2005-03-30T22:55:00Z</modified>
<issued>2005-03-30T22:54:15Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.751</id>
<created>2005-03-30T22:54:15Z</created>
<summary type="text/plain">April 6 Rob and Doyle and Chris Hathaway and April 8 Kawika and Andrew Harris and Ben Booth and Brad...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Projects</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>April 6 Rob and Doyle and Chris Hathaway and <br />
April 8 Kawika and Andrew Harris and Ben Booth and Brad</p>]]>

</content>
</entry>
<entry>
<title>More about improvement presentations</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/more_about_impr.html" />
<modified>2005-03-30T21:35:50Z</modified>
<issued>2005-03-30T21:35:50Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.749</id>
<created>2005-03-30T21:35:50Z</created>
<summary type="text/plain">YOu have to write a presentation and describe your favorite improvement. That presentation should go about 10 minutes and you should allow a few minutes for questions. The TAs will use the following form to evaluate your presentation:...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Projects</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>YOu have to write a presentation and describe your favorite improvement.  That presentation should go about 10 minutes and you should allow a few minutes for questions.  The TAs will use the following form to evaluate your presentation: </p>]]>
<![CDATA[<ol>
<li> Content [60 points]:  Could you understand what they did for their improvement?  Did you know what their improvement was supposed to accomplish?  Did they present enough data so that you could conclude that their improvement did or did not accomplish its objective?  Did their conclusion about their improvement match the data they presented?  Did they have any idea why their improvement did or did not work ? Did they have any ideas for what to do next to either improve their improvement or try something else? 
<li> Visual Presentation [20 points]: Were the slides readable?  Was the data well-presented?  Were the slides tacky and distracting?  Did they look at their feet or the keyboard the whole time? 
<li> Oral presentation [20 points]:  Did they speak clearly?  Did they vary their tone and speed? 
</ol>  

<p>For 312, you will probably want to use an outline that goes something like this.  Variations are fine, you know the scoring criteria so have fun if you want to do something completely different.  <br />
<ol><br />
<li> INtroduction.  What problem does your improvement work on? (1 slide) <br />
<li> What is your improvement supposed to improve about your solution to that problem?  How do you know that this is a problem? (1 or 2 slides) <br />
<li> What is your improvement?  (1 or 2 slides)  This would be a good place to talk about how you implemented your improvement, but be careful not spend forever talking about coding. <br />
<li> Say wehter or not you think your improvement accomplished anything and then present some data that supports your conclusions.  (2-3 slides) <br />
<li> Close by saying why your improvement did or did not work and what you would change next if you had enough time. (1 slide). <br />
</ol> </p>

<p>I've posted a guide to <a href="http://vv.cs.byu.edu/~jones/cs312/writing-a-presentation.htm">writing presentations</a>.  It is written mostly for graduate students presenting research, but the ideas apply to presenting improvements.  You'll find that its pretty opinionated.  I can be pretty dogmatic when I want to be, and I did.  So try not to get caught up in that. </p>]]>
</content>
</entry>
<entry>
<title>Notes about TSP Algorithms</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/notes_about_tsp.html" />
<modified>2005-03-30T18:52:27Z</modified>
<issued>2005-03-30T18:50:35Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.748</id>
<created>2005-03-30T18:50:35Z</created>
<summary type="text/plain"> What to put in each node? - Reduced matrix - lower bound - included edges - excluded edges How to generate children? - one child for from “here” to every destination o probably not a good idea. Queue gets...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Lectures</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<PRE>
What to put in each node? 
-	Reduced matrix
-	lower bound
-	included edges
-	excluded edges 
How to generate children? 
-	one child for from “here” to every destination 
o	probably not a good idea. Queue gets too big too fast. 
-	Pick “here” and generate a child for the n closest cities.  N children per node. 
-	Include or exclude an edge to generate 2 children 
How to traverse the graph? 
	- best first search using a pruning function. 
A bounding function
	- the matrix reduction algorithm from Wednesday.
Way to generate initial solutions 
-	pick the smallest edge from A to X then smallest from X to next city (other than A) and so forth.  Then return to A. 
-	pick a permutation of the city list and try that. 
-	Its probably worth doing more than 1 of these trials, but not worth doing all the permutations. You have to find the sweet spot.  Well, in your improvement you can find it if that’s what you want to do. 

The algorithm. 

class node 
   members 
matrix matrix, bound bound, vector solution, 
Boolean optimal
etc; 
methods
	reduce // reduce the matrix and increase the 
bound accordingly. 
		NextEdgeToIncludeAndExclude 
// pick an edge that maximizes exclude child’s bound or some other strategy. 
		excludeCityEdge (i,j) 
// excludes the edge from i to j, re-reduces the matrix and increases the bound as needed. 
Algorithm tsp-bb (matrix M)
: (vector v, int cost, bool optimal) 
priorityQueue of nodes pq; 

// set up my bssf. 
node bssf;  // best solution so far. 
(bssf.vector, bssf.bound) = 
min (several different solutions);
bssf.matrix = M; 
bssf.optimal = false; 

// build initial node. 
inode.matrix = M; 
inode.bound = 0; 
inode.reduce(); 
pq.push (inode);  

while (!pq.empty) {
	if (time has expired) 
then bssf.optimal = false; 
  break; 
 	curnode = pq.pop (); 
	(i,j) = curnode.NextCityEdgeToIncludeAndExclude(); 
	node include = new node(curnode); 
	node exclude = new node(curnode); 
	exclude.excludeCityEdge (i,j); 
	include.includeCityEdge (i,j); 
	if (include.isASolution() 
&& include.bound < bssf.bound)
		updateBSSF (include); // set optimal = true.  
		pq.prune();  
	// the order here matters, and you can use an else 
	// to simplify the code. 
if (include.bound < bssf.bound) 
pq.push (include); 
	if (exclude.bound < bssf.bound) 
	pq.push (exclude);  
}
// return the bssf. 
return bssf

Class node (int,int) NextCityEdgeToIncludeAndExclude () 
	// one strategy is to minimize bound on include-child.
	For each (i,j) such that M[i,j] = 0 
		M’ = copy of array M 
		Set row i = infinity and column j = infinity
		Set M’[j,i] = infinity 
		Difference = Reduce (M’) – bound 
		// another method… 
		If M[k,m] = 0 then
			Difference = min (row m) + min (column k) 
							Excluding M[k,m]. 
//Just a sketch.  Have fun and design your // own. 
Let i,j = M[i,j] so that we get the include and exlcude bounds we want.
// make sure there are no premature cycles. 
Use an array called “to” that tracks where you go “to” from city i. 
Write a for-loop to see if city i is connected to itself in less than n steps where n = # of cities. 
If i,j causes a premature them replace M[i,j} with infinity, reduce and try again. 
</pre> 
]]>

</content>
</entry>
<entry>
<title>An Access Database with more TSP Examples</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/an_access_datab.html" />
<modified>2005-03-30T17:37:15Z</modified>
<issued>2005-03-30T17:37:15Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.747</id>
<created>2005-03-30T17:37:15Z</created>
<summary type="text/plain">A kind student has created an access database with more TSP examples Warning: some lines have a preceeding space on their row definition and others do not....</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Projects</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>A kind student has created an <a href="http://students.cs.byu.edu/~cs312ta/handouts/w05-001/tspGraphs.mdb">access database with more TSP examples</a> </p>

<p>Warning:  some lines have a preceeding space on their row definition and others do not. </p>]]>

</content>
</entry>
<entry>
<title>More TSP Problems</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/more_tsp_proble.html" />
<modified>2005-03-28T17:41:16Z</modified>
<issued>2005-03-28T17:41:16Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.745</id>
<created>2005-03-28T17:41:16Z</created>
<summary type="text/plain">We have created an archive with more tsp problems. They aren&apos;t in an access database, you get to do that tedious step yourself. If you do put them in the database you are invited to send that database to me...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Projects</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>We have created an archive with <a href="http://students.cs.byu.edu/~cs312ta/handouts/w05-001/tspGraphs.tar.bz2">more tsp problems</a>.  They aren't in an access database, you get to do that tedious step yourself.  <br />
If you do put them in the database you are invited to send that database to <a href="mailto:jones@cs.byu.edu">me</a> and I will distribute it. </p>]]>

</content>
</entry>
<entry>
<title>The plan for the rest of the semester</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/the_plan_for_th.html" />
<modified>2005-03-28T15:52:33Z</modified>
<issued>2005-03-28T15:52:33Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.743</id>
<created>2005-03-28T15:52:33Z</created>
<summary type="text/plain">We will wrap up the TSP algorithm today. Wednesday (3/30) we will do the minimax algorithm and start linear programing if time permits. Friday (4/1) we will go into linear programing in earnest and stick with that through the last...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Schedule</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[<p>We will wrap up the TSP algorithm today.  Wednesday (3/30) we will do the minimax algorithm and start linear programing if time permits.  Friday (4/1) we will go into linear programing in earnest and stick with that through the last day of class. <br />
Linear programing is not in the textbook.  A handout will be made available before 4/1.  Linear programing is an important topic because it gives you another way to think about optimization problems and ties together most of hte ideas from the whole course. <br />
The last project is to code up the simplex method.  In linear programming problems, half the "fun" is coming up with the formulation of the problem as a linear program.  So this project will be a little different.  We will give you a constraint satisfaction problem and you will formulate it as a linear program, convert it to slack form, implement the simplex method and use your implementation to solve the slack form of your linear program.  That will simplify the project a little while focusing on the main ideas.  </p>]]>

</content>
</entry>
<entry>
<title>Putting the TSP Algorithm Together</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/putting_the_tsp.html" />
<modified>2005-03-26T02:51:17Z</modified>
<issued>2005-03-26T02:50:52Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.740</id>
<created>2005-03-26T02:50:52Z</created>
<summary type="text/plain">This is the algorithm so far. We will continue fleshing out the details on Monday....</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Lectures</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
This is the algorithm so far.  We will continue fleshing out the details on Monday. 
<![CDATA[<pre>
What to put in each node?
-	Reduced matrix
-	lower bound
-	included edges
-	excluded edges
How to generate children?
-	one child for from “here” to every destination
o	probably not a good idea. Queue gets too big too fast.
-	Pick “here” and generate a child for the n closest cities.  N children
per node.
-	Include or exclude an edge to generate 2 children
How to traverse the graph?
	- best first search using a pruning function.
A bounding function
	- the matrix reduction algorithm from Wednesday.
Way to generate initial solutions
-	pick the smallest edge from A to X then smallest from X to next city
(other than A) and so forth.  Then return to A.
-	pick a permutation of the city list and try that.
-	Its probably worth doing more than 1 of these trials, but not worth
doing all the permutations. You have to find the sweet spot.  Well, in
your improvement you can find it if that’s what you want to do.

The algorithm.

class node
   members
matrix matrix, bound bound, vector solution,
Boolean optimal
etc;
methods
	reduce // reduce the matrix and increase the
bound accordingly.
		NextEdgeToIncludeAndExclude
// pick an edge that maximizes exclude child’s bound or some other strategy.
		excludeCityEdge (i,j)
// excludes the edge from i to j, re-reduces the matrix and increases the
bound as needed.
Algorithm tsp-bb (matrix M)
: (vector v, int cost, bool optimal)
priorityQueue of nodes pq;

// set up my bssf.
node bssf;  // best solution so far.
(bssf.vector, bssf.bound) =
min (several different solutions);
bssf.matrix = M;
bssf.optimal = false;

// build initial node.
inode.matrix = M;
inode.bound = 0;
inode.reduce();
pq.push (inode);

while (!pq.empty) {
	curnode = pq.pop ();
	(i,j) = curnode.NextCityEdgeToIncludeAndExclude();
	node include = new node(curnode);
	node exclude = new node(curnode);
	exclude.excludeCityEdge (i,j);
	include.includeCityEdge (i,j);
	if (include.isASolution()
&& include.bound < bssf.bound)
		updateBSSF (include);
		pq.prune();
	// the order here matters, and you can use an else
	// to simplify the code.
if (include.bound < bssf.bound)
pq.push (include);
	if (exclude.bound < bssf.bound)
	pq.push (exclude);
}
</pre>]]>
</content>
</entry>
<entry>
<title>Avoiding premature cycles (due 3/30)</title>
<link rel="alternate" type="text/html" href="http://vv.cs.byu.edu/cs312-003/archives/2005/03/avoiding_premat.html" />
<modified>2005-03-31T15:52:59Z</modified>
<issued>2005-03-25T22:45:25Z</issued>
<id>tag:vv.cs.byu.edu,2005:/cs312-003/5.739</id>
<created>2005-03-25T22:45:25Z</created>
<summary type="text/plain">Answer the following questions: What is a premature cycle? Are premature cycles possible in the include/exclude formulation of the problem? That&apos;s the algorithm that picks an edge to include and exclude resulting in two new nodes. Sketch an algorithm and...</summary>
<author>
<name>jones</name>
<url>http://vv.cs.byu.edu/~jones/blog</url>
<email>jones@cs.byu.edu</email>
</author>
<dc:subject>Homework</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://vv.cs.byu.edu/cs312-003/">
<![CDATA[Answer the following questions: 
<ol>
<li> What is a premature cycle? 
<li> Are premature cycles possible in the include/exclude formulation of the problem?  That's the algorithm that picks an edge to include and exclude resulting in two new nodes.  
<li> Sketch an algorithm and accompnying datastractures for detecting premature cycles as they are formed. 
<li> Make sure you can detect premature cycles and that you can detect completed cycles too. 
</ol>]]>
<![CDATA[<b>Solution</b><p>
The other questions are pretty straightfoward, here's a premature cycle detection algorithm... 
<pre>
array to of int[n]. // an array that lives in each nod.e 

is edge (x,y) ok to add? 
int here;
here = y;  // note that I didn't modify the "to" array. 
for (i = 1 ; i < n; i++)   // since I started at y (rather than x) I only go up to n-1 in a solution. 
    here = to[here]; 
    if (here == x) then return false // not ok to add x,y. 
return true // it is ok to add x,y. 
</pre> ]]>
</content>
</entry>

</feed>