<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Felipe Barriga Richards &#187; lp_solve</title>
	<atom:link href="http://blog.felipebarriga.cl/tag/lp_solve/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.felipebarriga.cl</link>
	<description>Blog personal de Felipe Barriga Richards</description>
	<lastBuildDate>Thu, 29 Dec 2011 17:15:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Solve Progressive Party Problem (PPP) with ZIMPL and lp_solve</title>
		<link>http://blog.felipebarriga.cl/programacion/solve-progressive-party-problem-ppp-zimpl-lp_solve/</link>
		<comments>http://blog.felipebarriga.cl/programacion/solve-progressive-party-problem-ppp-zimpl-lp_solve/#comments</comments>
		<pubDate>Tue, 18 May 2010 02:33:16 +0000</pubDate>
		<dc:creator>fbarriga</dc:creator>
				<category><![CDATA[Programacion]]></category>
		<category><![CDATA[lp_solve]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[ppp]]></category>
		<category><![CDATA[zimpl]]></category>

		<guid isPermaLink="false">http://blog.felipebarriga.cl/?p=370</guid>
		<description><![CDATA[Introduction Here is a model to solve the Progressive Party Problem using ZIMPL as the modeling language and lp_solve as the solver. This model is to minimize the number of host boats. Model The model need optimizations but it works. The data is separated from the code so is easy to change the instance to [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Here is a model to solve the <a href="http://www.ps.uni-saarland.de/~walser/ppp/ppp.html">Progressive Party Problem</a> using <a href="http://zimpl.zib.de/">ZIMPL</a> as the modeling language and <a href="http://lpsolve.sourceforge.net/5.5/">lp_solve</a> as the solver. This model is to minimize the number of host boats.<br />
<span id="more-370"></span><br/></p>
<h2>Model</h2>
<p>The model need optimizations but it works. The data is separated from the code so is easy to change the instance to test. You only need to change 4 lines in the code and replace the instance. All the files are <em>.txt</em> because wordpress don&#8217;t allow me to upload files with other extensions. Originally the model is <em>.zpl</em> and the data is <em>.dat</em></p>
<p>Model:</p>
<ul>
<li>Model: <a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp.txt'>ppp.txt</a></li>
<li>Data (8 boats, 2 periods): <a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_008_2.txt'>ppp_008_2.txt</a></li>
</ul>
<p><br/></p>
<h2>Results</h2>
<p>After running ZIMPL and lp_solve a solution file will be created and then parsed with the scripts that are in another section of this page. I do several test changing the params of lp_solve and you can check the results on the &#8220;Benchmark parameters&#8221; section. The only instance that I can resolve is the one with 8 boats and 2 periods, the other take to much time.</p>
<p>Then you can see the solution file (I remove some lines without useful information with the script <em>simplify_solution.sh</em>):<br />
<code><br />
isGuest$boat1 1<br />
isGuest$boat3 1<br />
isGuest$boat4 1<br />
isGuest$boat6 1<br />
isHost$boat2 1<br />
isHost$boat5 1<br />
isHost$boat7 1<br />
isHost$boat8 1<br />
visit$boat1$boat2#1 1<br />
visit$boat1$boat5#2 1<br />
visit$boat3$boat2#2 1<br />
visit$boat3$boat5#1 1<br />
visit$boat4$boat2#1 1<br />
visit$boat4$boat7#2 1<br />
visit$boat6$boat5#2 1<br />
visit$boat6$boat7#1 1<br />
meet$boat1$boat4#1 1<br />
meet$boat1$boat6#2 1<br />
meet$boat3$boat1#2 1<br />
meet$boat4$boat1#1 1<br />
meet$boat6$boat1#2 1<br />
</code></p>
<p>After interpreting it this is what you get:<br />
<code><br />
Host:  &nbsp;2 5 7 8<br />
Guest: 1 3 4 6</p>
<p>Visits:<br />
boat1: 2 5<br />
boat3: 5 2<br />
boat4: 2 7<br />
boat6: 7 5<br />
</code><br />
<font color="red"><br />
If you see there is no error on the solution <u>but there is a problem in the model</u> because it says that <em>boat3</em> meet <em>boat1</em> in <em>period 2</em> (<strong>meet$boat3$boat1#2 1</strong>) and that isn&#8217;t true ! If someone find the solution please send an email.</font><br />
<br/></p>
<h2>Complementary Scripts</h2>
<p>&nbsp;<br />

<div class='easySpoilerWrapper' style=''>
<table class='easySpoilerTable' border='0' style='text-align:center;' align='center' bgcolor='FFFFFF' >

<tr style='white-space:normal;'><th class='easySpoilerTitleA'  style='white-space:normal;font-weight:normal;text-align:left;vertical-align:middle;font-size:120%;color:#000000;'>Spoiler Inside: Translate model and execute solver: solve.sh</th>
<th class='easySpoilerTitleB'  style='text-align:right;vertical-align:middle;font-size:100%; white-space:nowrap;'>
<a href='' onclick='wpSpoilerSelect("spoilerDiv69ca8001"); return false;' class='easySpoilerButtonOther' style='font-size:100%;color:#000000;background-color:#fcfcfc;background-image:none;border: 1px inset;border-style:solid;border-color:#cccccc;  margin: 3px 0px 3px; padding: 4px; ' align='right'>Select</a><a href='' onclick='wpSpoilerToggle("spoilerDiv69ca8001",true,"Show","Hide","fast",false); return false;' id='spoilerDiv69ca8001_action' class='easySpoilerButton' value="Show" align='right' style='font-size:100%;color:#000000;background-color:#fcfcfc;background-image:none;border: 1px inset;border-style:solid;border-color:#cccccc; margin: 3px 0px 3px 5px; padding: 4px;"'>Show</></th>
</tr>
<tr><td class='easySpoilerRow' colspan='2' style=''><div id='spoilerDiv69ca8001' class='easySpoilerSpoils'  style='display:none; white-space:wrap; overflow:auto; vertical-align:middle;'>
<br />
<code>
<pre>
#!/bin/bash

if [ $# -ne 1 ]
then
	echo "Usage: "
	echo -e "\t ${0} solution_name"
	echo -e "\t Example:"
	echo -e "\t\t ${0} ppp"
	exit -1
fi

if [ ! -f $1.txt ]
then
	echo "There is no model file ${1}.txt"
	exit -1
fi

zimpl -t mps -O $1.txt &#038;&#038; lp_solve -time -mps -presolve $1.mps  > $1.solution
</pre>
<p></code><br />
Execute with:</p>

<div class="wp-terminal"><font color='#33FF00'>felipe@funstation</font> <font color='#0066FF'>$</font> ./solve.sh ppp<br/></div>

<p>
</div></td></tr>
</table>
<div class='easySpoilerConclude' style=''><table class='easySpoilerTable' border='0' style='text-align:center;' frame='box' align='center' bgcolor='FFFFFF'><tr><th class='easySpoilerEnd' style='width:100%;'></th><td class='easySpoilerEnd' style='white-space:nowrap;' colspan='2'></td></tr><tr><td class='easySpoilerGroupWrapperLastRow' colspan='2' style=''></td></tr></table></div>
</div>
<br />
&nbsp;<br />

<div class='easySpoilerWrapper' style=''>
<table class='easySpoilerTable' border='0' style='text-align:center;' align='center' bgcolor='FFFFFF' >

<tr style='white-space:normal;'><th class='easySpoilerTitleA'  style='white-space:normal;font-weight:normal;text-align:left;vertical-align:middle;font-size:120%;color:#000000;'>Spoiler Inside: Replace the variables name on solution file: translate.sh</th>
<th class='easySpoilerTitleB'  style='text-align:right;vertical-align:middle;font-size:100%; white-space:nowrap;'>
<a href='' onclick='wpSpoilerSelect("spoilerDiv79d38002"); return false;' class='easySpoilerButtonOther' style='font-size:100%;color:#000000;background-color:#fcfcfc;background-image:none;border: 1px inset;border-style:solid;border-color:#cccccc;  margin: 3px 0px 3px; padding: 4px; ' align='right'>Select</a><a href='' onclick='wpSpoilerToggle("spoilerDiv79d38002",true,"Show","Hide","fast",false); return false;' id='spoilerDiv79d38002_action' class='easySpoilerButton' value="Show" align='right' style='font-size:100%;color:#000000;background-color:#fcfcfc;background-image:none;border: 1px inset;border-style:solid;border-color:#cccccc; margin: 3px 0px 3px 5px; padding: 4px;"'>Show</></th>
</tr>
<tr><td class='easySpoilerRow' colspan='2' style=''><div id='spoilerDiv79d38002' class='easySpoilerSpoils'  style='display:none; white-space:wrap; overflow:auto; vertical-align:middle;'>
<br />
<code>
<pre>
#!/bin/bash

if [ $# -ne 1 ]
then
	echo "Usage: "
	echo -e "\t ${0} solution_name"
	echo -e "\t Example:"
	echo -e "\t\t ${0} ppp"
	exit -1
fi

if [ ! -f $1.solution ]
then
	echo "There is no solution file ${1}.solution"
	exit -1
fi

if [ ! -f $1.tbl ]
then
	echo "There is no table file ${1}.tbl"
	exit -1
fi

cat $1.tbl | while read a b c src dst
do
	dst2=`echo ${dst} | tr -d '"'`
	if [ ! -z src ]
	then
		if [ ${src:0:1} == "_" ]
		then
			exit 0
		fi
		sed "s/${src}/${dst2}/g" < $1.solution > $1.solution_tmp
		mv -f $1.solution_tmp $1.solution
	else
		exit 0
	fi
done
</pre>
<p></code><br />
Execute with:<br/></p>

<div class="wp-terminal"><font color='#33FF00'>felipe@funstation</font> <font color='#0066FF'>$</font> ./simplify_solution.sh ppp<br/></div>

<p>
</div></td></tr>
</table>
<div class='easySpoilerConclude' style=''><table class='easySpoilerTable' border='0' style='text-align:center;' frame='box' align='center' bgcolor='FFFFFF'><tr><th class='easySpoilerEnd' style='width:100%;'></th><td class='easySpoilerEnd' style='white-space:nowrap;' colspan='2'></td></tr><tr><td class='easySpoilerGroupWrapperLastRow' colspan='2' style=''></td></tr></table></div>
</div>
<br />
&nbsp;<br />

<div class='easySpoilerWrapper' style=''>
<table class='easySpoilerTable' border='0' style='text-align:center;' align='center' bgcolor='FFFFFF' >

<tr style='white-space:normal;'><th class='easySpoilerTitleA'  style='white-space:normal;font-weight:normal;text-align:left;vertical-align:middle;font-size:120%;color:#000000;'>Spoiler Inside: Simplify the solution file: simplify_solution.sh</th>
<th class='easySpoilerTitleB'  style='text-align:right;vertical-align:middle;font-size:100%; white-space:nowrap;'>
<a href='' onclick='wpSpoilerSelect("spoilerDiv10008003"); return false;' class='easySpoilerButtonOther' style='font-size:100%;color:#000000;background-color:#fcfcfc;background-image:none;border: 1px inset;border-style:solid;border-color:#cccccc;  margin: 3px 0px 3px; padding: 4px; ' align='right'>Select</a><a href='' onclick='wpSpoilerToggle("spoilerDiv10008003",true,"Show","Hide","fast",false); return false;' id='spoilerDiv10008003_action' class='easySpoilerButton' value="Show" align='right' style='font-size:100%;color:#000000;background-color:#fcfcfc;background-image:none;border: 1px inset;border-style:solid;border-color:#cccccc; margin: 3px 0px 3px 5px; padding: 4px;"'>Show</></th>
</tr>
<tr><td class='easySpoilerRow' colspan='2' style=''><div id='spoilerDiv10008003' class='easySpoilerSpoils'  style='display:none; white-space:wrap; overflow:auto; vertical-align:middle;'>
<br />
<code>
<pre>
#!/bin/bash

if [ $# -ne 1 ]
then
	echo "Usage: "
	echo -e "\t ${0} solution_name"
	echo -e "\t Example:"
	echo -e "\t\t ${0} ppp"
	exit -1
fi

if [ ! -f $1.solution ]
then
	echo "There is no solution file ${1}.solution"
	exit -1
fi

rm -f ${1}.simplified_solution
cat $1.solution | while read a b c
do
	if [ ! -z "$a" -a ! -z "$b" ]
	then
		if [ ${a:0:1} != "_" -a $b == "1" ]
		then
			echo "${a} ${b}" >> ${1}.simplified_solution
		fi
	fi
done
</pre>
<p></code><br />
Execute with:<br/></p>

<div class="wp-terminal"><font color='#33FF00'>felipe@funstation</font> <font color='#0066FF'>$</font> ./simplify_solution.sh ppp<br/></div>

<p>
</div></td></tr>
</table>
<div class='easySpoilerConclude' style=''><table class='easySpoilerTable' border='0' style='text-align:center;' frame='box' align='center' bgcolor='FFFFFF'><tr><th class='easySpoilerEnd' style='width:100%;'></th><td class='easySpoilerEnd' style='white-space:nowrap;' colspan='2'></td></tr><tr><td class='easySpoilerGroupWrapperLastRow' colspan='2' style=''></td></tr></table></div>
</div>
<br />
&nbsp;</p>
<h2>Benchmark of lp_solve params</h2>
<p>I make some test to see how the different parameters affect the speed of lp_solve. The instance tested is the one with 8 boats and 2 periods under a Core 2 Duo at 1.73GHz. Also I try replacing the constrain <strong>&#8220;forall <host> in Boat &#8211; {guest} do&#8221;</strong> with <strong>&#8220;forall <host> in Boat with (guest != host) do&#8221;</strong>. Here is a table showing the results:<br />
<center></p>
<table style="text-align: center; border: 1px solid black;">
<tr>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;constrain&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;params&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td><strong>&nbsp;&nbsp;CPU time [in seconds]&nbsp;&nbsp;</strong></td>
</tr>
<tr>
<td>(guest != host)</td>
<td>none</td>
<td>197.72</td>
</tr>
<tr>
<td>(guest != host)</td>
<td>-presolve</td>
<td>104.58</td>
</tr>
<tr>
<td>(guest != host)</td>
<td>-Bd</td>
<td>659.82</td>
</tr>
<tr>
<td>(guest != host)</td>
<td>-Bd -presolve</td>
<td>786.86</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>none</td>
<td>242.47</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolve</td>
<td>76.2</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolvem</td>
<td>95.17</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolveq</td>
<td>150.51</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolves</td>
<td>171.44</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolvel</td>
<td>171.84</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolver</td>
<td>225.69</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolvecold</td>
<td>242.02</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolvek</td>
<td>244.67</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolvefd</td>
<td>247.02</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolverowd</td>
<td>248.04</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolvebnd</td>
<td>249.06</td>
</tr>
<tr>
<td>Boat &#8211; {guest}</td>
<td>-presolveb</td>
<td>250.35</td>
</tr>
</table>
<p></center><br />
<br/></p>
<h2>More Results</h2>
<p><center></p>
<table style="text-align: center; border: 1px solid black;">
<tr>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;boats&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;periods&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;min hosts found&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;time [seconds]&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
<td><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></td>
</tr>
<tr>
<td>4</td>
<td>1</td>
<td>2</td>
<td>0.01</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_004_1.txt'>ppp_004_1.txt</a></td>
</tr>
<tr>
<td>5</td>
<td>1</td>
<td>2</td>
<td>0.1</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_005_1.txt'>ppp_005_1.txt</a></td>
</tr>
<tr>
<td>6</td>
<td>1</td>
<td>3</td>
<td>0.15</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_006_1.txt'>ppp_006_1.txt</a></td>
</tr>
<tr>
<td>7</td>
<td>1</td>
<td>3</td>
<td>3.69</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_007_1.txt'>ppp_007_1.txt</a></td>
</tr>
<tr>
<td>8</td>
<td>2</td>
<td>4</td>
<td>76.2</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_008_2.txt'>ppp_008_2.txt</a></td>
</tr>
<tr>
<td>9</td>
<td>3</td>
<td>?</td>
<td>?</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_009_3.txt'>ppp_009_3.txt</a></td>
</tr>
<tr>
<td>10</td>
<td>2</td>
<td>?</td>
<td>?</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_010_2.txt'>ppp_010_2.txt</a></td>
</tr>
<tr>
<td>21</td>
<td>6</td>
<td>?</td>
<td>?</td>
<td><a href='http://blog.felipebarriga.cl/wp-content/uploads/2010/05/ppp_021_6.txt'>ppp_021_6.txt</a></td>
</tr>
</table>
<p></center></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.felipebarriga.cl/programacion/solve-progressive-party-problem-ppp-zimpl-lp_solve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

