Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > df736a3bc446df5b16150bebb7296274 > files > 306

DSDP-devel-5.8-2.fc14.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>DSDP: examples/stable.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">DSDP</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_0a4f0a65bb1e36a4913e16ae18cb477d.html">examples</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">stable.c</div>  </div>
</div>
<div class="contents">
<a href="stable_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="dsdp5_8h.html" title="The API to DSDP for those applications using DSDP as a subroutine library.">dsdp5.h</a>&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00006"></a>00006 
<a name="l00011"></a>00011 <span class="keywordtype">char</span> help[]=<span class="stringliteral">&quot;\n\</span>
<a name="l00012"></a>00012 <span class="stringliteral">Compute the stable set for a graph. \n\n\</span>
<a name="l00013"></a>00013 <span class="stringliteral">DSDP Usage: stable &lt;graph filename&gt; \n&quot;</span>;
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="keyword">typedef</span> <span class="keyword">struct </span>{
<a name="l00016"></a>00016   <span class="keywordtype">double</span> v[3];
<a name="l00017"></a>00017   <span class="keywordtype">int</span> indd[3];
<a name="l00018"></a>00018 } EdgeMat;
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="keyword">static</span> <span class="keywordtype">int</span> ReadGraphFromFile(<span class="keywordtype">char</span>*,<span class="keywordtype">int</span>*, <span class="keywordtype">int</span>*, EdgeMat*[]); 
<a name="l00021"></a>00021 <span class="keywordtype">int</span> <a class="code" href="group__Examples.html#ga2ca7521594b54a0d5a74a72f8293650b" title="Given a graph, formulate maximum Stable Set problem and place data into solver.">SetStableSetData</a>(<a class="code" href="structDSDP__C.html" title="Internal structures for the DSDP solver.">DSDP</a>, <a class="code" href="structSDPCone__C.html" title="Internal structure for semidefinite cone.">SDPCone</a>, <span class="keywordtype">int</span>, <span class="keywordtype">int</span>, EdgeMat[]);
<a name="l00022"></a>00022 <span class="keywordtype">int</span> <a class="code" href="group__Examples.html#ga302186dee2a32446540218c3b940eb48" title="Formulate and solve the maximum Stable Set problem.">StableSet</a>(<span class="keywordtype">int</span> argc,<span class="keywordtype">char</span> *argv[]);
<a name="l00023"></a>00023 <span class="keywordtype">int</span> <a class="code" href="group__Examples.html#ga19a56f8df210e5a7ba6e0970e5c9187a" title="Apply a randomized procedure to find feasible stable sets.">StableRandomized</a>(<a class="code" href="structSDPCone__C.html" title="Internal structure for semidefinite cone.">SDPCone</a>,<span class="keywordtype">int</span>, <span class="keywordtype">int</span>, EdgeMat[]);
<a name="l00024"></a>00024 <span class="preprocessor">#define CHKERR(a)  { if (a){printf(&quot;DSDP Numerical Error or Memory Problem&quot;); return 2;} }</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span>
<a name="l00026"></a>00026 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc,<span class="keywordtype">char</span> *argv[]){
<a name="l00027"></a>00027   <span class="keywordtype">int</span> info;
<a name="l00028"></a>00028   info=<a class="code" href="group__Examples.html#ga302186dee2a32446540218c3b940eb48" title="Formulate and solve the maximum Stable Set problem.">StableSet</a>(argc,argv);
<a name="l00029"></a>00029   <span class="keywordflow">return</span> 0;
<a name="l00030"></a>00030 }
<a name="l00031"></a>00031 
<a name="l00040"></a><a class="code" href="group__Examples.html#ga302186dee2a32446540218c3b940eb48">00040</a> <span class="keywordtype">int</span> <a class="code" href="group__Examples.html#ga302186dee2a32446540218c3b940eb48" title="Formulate and solve the maximum Stable Set problem.">StableSet</a>(<span class="keywordtype">int</span> argc,<span class="keywordtype">char</span> *argv[]){
<a name="l00041"></a>00041 
<a name="l00042"></a>00042   <span class="keywordtype">int</span> info,kk,nedges,nnodes;
<a name="l00043"></a>00043   EdgeMat *Edges;
<a name="l00044"></a>00044   <a class="code" href="structDSDP__C.html" title="Internal structures for the DSDP solver.">DSDP</a> dsdp;
<a name="l00045"></a>00045   <a class="code" href="structSDPCone__C.html" title="Internal structure for semidefinite cone.">SDPCone</a>  sdpcone;
<a name="l00046"></a>00046 
<a name="l00047"></a>00047   <span class="keywordflow">if</span> (argc&lt;2){ printf(<span class="stringliteral">&quot;%s&quot;</span>,help); <span class="keywordflow">return</span>(1); }
<a name="l00048"></a>00048 
<a name="l00049"></a>00049   info = ReadGraphFromFile(argv[1],&amp;nnodes,&amp;nedges,&amp;Edges);
<a name="l00050"></a>00050   <span class="keywordflow">if</span> (info){ printf(<span class="stringliteral">&quot;Problem reading file\n&quot;</span>); <span class="keywordflow">return</span> 1; }
<a name="l00051"></a>00051 
<a name="l00052"></a>00052   info = <a class="code" href="group__DSDPBasic.html#gaa32509ded8359326d02782adb91c745a" title="Create a DSDP solver. FIRST DSDP routine!">DSDPCreate</a>(nedges+nnodes+1,&amp;dsdp);CHKERR(info); 
<a name="l00053"></a>00053   info = DSDPCreateSDPCone(dsdp,1,&amp;sdpcone);CHKERR(info); 
<a name="l00054"></a>00054   info = <a class="code" href="group__SDPRoutines.html#ga0c3a5c6eee6aca0ab0c222fbfcca1d19" title="Set the dimension of one block in the semidefinite cone.">SDPConeSetBlockSize</a>(sdpcone,0,nnodes+1);CHKERR(info); 
<a name="l00055"></a>00055   info = <a class="code" href="group__SDPData.html#gaa3747efc8ae918a9be9138dcab3cf7bd" title="Use packed symmetric format for the dense array.">SDPConeUsePackedFormat</a>(sdpcone,0);CHKERR(info); 
<a name="l00056"></a>00056   info = <a class="code" href="group__SDPRoutines.html#ga40728695e4c841900c02c615a8d96ab0" title="Set the number of nonzero matrices in a block of the semidefinite cone.">SDPConeSetSparsity</a>(sdpcone,0,nedges+nnodes+1);CHKERR(info); 
<a name="l00057"></a>00057   info = <a class="code" href="group__Examples.html#ga2ca7521594b54a0d5a74a72f8293650b" title="Given a graph, formulate maximum Stable Set problem and place data into solver.">SetStableSetData</a>(dsdp, sdpcone, nnodes, nedges, Edges);
<a name="l00058"></a>00058   <span class="keywordflow">if</span> (info){ printf(<span class="stringliteral">&quot;Problem setting data\n&quot;</span>); <span class="keywordflow">return</span> 1; }
<a name="l00059"></a>00059 
<a name="l00060"></a>00060   info = <a class="code" href="group__DSDPConverge.html#ga4c0fa6941c40cca7643c2f4a9ae813bf" title="Terminate the solver when the relative duality gap is less than this tolerance.">DSDPSetGapTolerance</a>(dsdp,0.0001);CHKERR(info); 
<a name="l00061"></a>00061   info = <a class="code" href="group__DSDPSolver.html#ga2795069b8aaa6551a8c1c248bbb2cb1a" title="Set an upper bound on the objective value at the solution.">DSDPSetZBar</a>(dsdp,1e10*nnodes+1);CHKERR(info); 
<a name="l00062"></a>00062   info = <a class="code" href="group__DSDPSolver.html#ga903ff948f2ba766430ba3918b9447ee7" title="Reuse the Hessian of the barrier function multiple times at each DSDP iteration.">DSDPReuseMatrix</a>(dsdp,10);CHKERR(info); 
<a name="l00063"></a>00063 
<a name="l00064"></a>00064   <span class="keywordflow">for</span> (kk=1; kk&lt;argc-1; kk++){
<a name="l00065"></a>00065     <span class="keywordflow">if</span> (strncmp(argv[kk],<span class="stringliteral">&quot;-dloginfo&quot;</span>,8)==0){
<a name="l00066"></a>00066       info=DSDPLogInfoAllow(<a class="code" href="dsdpbasictypes_8h.html#ae667f2bff3ab5ab0bc109fa76dc4ed65ae6b2e53e51e94a5fa7204ceac78f824f">DSDP_TRUE</a>,0);CHKERR(info); 
<a name="l00067"></a>00067     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(argv[kk],<span class="stringliteral">&quot;-params&quot;</span>,7)==0){
<a name="l00068"></a>00068       info=<a class="code" href="group__DSDPSolver.html#gab1340aac2a0c79108be725389f481979" title="Read DSDP parameters from a file.">DSDPReadOptions</a>(dsdp,argv[kk+1]);CHKERR(info); 
<a name="l00069"></a>00069     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strncmp(argv[kk],<span class="stringliteral">&quot;-help&quot;</span>,5)==0){
<a name="l00070"></a>00070       printf(<span class="stringliteral">&quot;%s\n&quot;</span>,help);
<a name="l00071"></a>00071     } 
<a name="l00072"></a>00072   }
<a name="l00073"></a>00073   info=<a class="code" href="group__DSDPBasic.html#ga5f1941aaedfa888e940bad968ac0d847" title="Read command line arguments to set options in DSDP.">DSDPSetOptions</a>(dsdp,argv,argc);CHKERR(info); 
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   info = <a class="code" href="group__DSDPBasic.html#ga945023e6d663d0897d3d04a7d738608d" title="Print at every kth iteration.">DSDPSetStandardMonitor</a>(dsdp,1);CHKERR(info); 
<a name="l00076"></a>00076 
<a name="l00077"></a>00077   info = <a class="code" href="group__DSDPBasic.html#ga2bd311ea1ecad8f690255b8a35f694a0" title="Set up data structures in the solver and the cones associated with it.">DSDPSetup</a>(dsdp);CHKERR(info); 
<a name="l00078"></a>00078   <span class="keywordflow">if</span> (0==1){info=<a class="code" href="group__SDPData.html#ga479e45b5543849df14aa0d1c56e25753" title="Check the matrix operations on a data matrix;.">SDPConeCheckData</a>(sdpcone);}
<a name="l00079"></a>00079   
<a name="l00080"></a>00080   info=<a class="code" href="group__DSDPBasic.html#gabf7f1440bad5dd2a609288912743c8e9" title="Apply DSDP to the problem.">DSDPSolve</a>(dsdp); CHKERR(info);
<a name="l00081"></a>00081   info=<a class="code" href="group__Examples.html#ga19a56f8df210e5a7ba6e0970e5c9187a" title="Apply a randomized procedure to find feasible stable sets.">StableRandomized</a>(sdpcone,nnodes,nedges,Edges);
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   info=<a class="code" href="group__DSDPBasic.html#gacd271769549030ce365597101946220b" title="Compute the X variables.">DSDPComputeX</a>(dsdp);CHKERR(info);
<a name="l00084"></a>00084   
<a name="l00085"></a>00085   <span class="keywordflow">if</span> (0==1){ <span class="comment">/* Look at the solution */</span>
<a name="l00086"></a>00086     <span class="keywordtype">int</span> n; <span class="keywordtype">double</span> *xx;
<a name="l00087"></a>00087     info=<a class="code" href="group__SDPBasic.html#ga9e7744a5c7fbe87642979e2b41bc2c00" title="After applying the solver, set a pointer to the array in the object with the solution X...">SDPConeGetXArray</a>(sdpcone,0,&amp;xx,&amp;n);CHKERR(info); 
<a name="l00088"></a>00088   }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090   info = <a class="code" href="group__DSDPBasic.html#ga3242b32d5e9c5e5358da5f79ae5d08dd" title="Free the internal data structures of the solver and the cones associated with it.">DSDPDestroy</a>(dsdp);CHKERR(info); 
<a name="l00091"></a>00091   free(Edges);
<a name="l00092"></a>00092   
<a name="l00093"></a>00093   <span class="keywordflow">return</span> 0;
<a name="l00094"></a>00094 } <span class="comment">/* main */</span>
<a name="l00095"></a>00095 
<a name="l00107"></a><a class="code" href="group__Examples.html#ga2ca7521594b54a0d5a74a72f8293650b">00107</a> <span class="keywordtype">int</span> <a class="code" href="group__Examples.html#ga2ca7521594b54a0d5a74a72f8293650b" title="Given a graph, formulate maximum Stable Set problem and place data into solver.">SetStableSetData</a>(<a class="code" href="structDSDP__C.html" title="Internal structures for the DSDP solver.">DSDP</a> dsdp, <a class="code" href="structSDPCone__C.html" title="Internal structure for semidefinite cone.">SDPCone</a> sdpcone, <span class="keywordtype">int</span> nodes, <span class="keywordtype">int</span> edges, EdgeMat Edge[]){
<a name="l00108"></a>00108 
<a name="l00109"></a>00109   <span class="keywordtype">int</span> i,ii,info,nnodes=nodes+1;
<a name="l00110"></a>00110   <span class="keywordtype">int</span> *iptr,*iptr2;
<a name="l00111"></a>00111   <span class="keywordtype">double</span> *diag;
<a name="l00112"></a>00112 
<a name="l00113"></a>00113   <span class="comment">/* The c matrix has all elements equal to 1.0 */</span>
<a name="l00114"></a>00114   diag=(<span class="keywordtype">double</span>*)malloc(nnodes*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00115"></a>00115   iptr=(<span class="keywordtype">int</span>*)malloc(nnodes*<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00116"></a>00116   iptr2=(<span class="keywordtype">int</span>*)malloc(nnodes*<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00117"></a>00117 
<a name="l00118"></a>00118   ii=nodes*(nodes+1)/2;
<a name="l00119"></a>00119   <span class="keywordflow">for</span> (i=0;i&lt;nnodes;i++){
<a name="l00120"></a>00120     diag[i]=1.0;
<a name="l00121"></a>00121     iptr[i]=i*(i+1)/2+i; 
<a name="l00122"></a>00122     iptr2[i]=i;
<a name="l00123"></a>00123   }
<a name="l00124"></a>00124   info = <a class="code" href="group__SDPBasic.html#gaa6ed45b2539266f04bd4b8401aa89c06" title="Set data matrix  in a sparse format.">SDPConeSetASparseVecMat</a>(sdpcone,0,0,nnodes,-0.50,0,iptr,diag,nodes);CHKERR(info); 
<a name="l00125"></a>00125   info = <a class="code" href="group__SDPData.html#ga16ceede5a0ddb2717ca40ffe2a5f3d2f" title="Add data matrix  in a sparse format.">SDPConeAddASparseVecMat</a>(sdpcone,0,0,nnodes,-0.25,-ii,iptr2,diag,nodes);CHKERR(info); 
<a name="l00126"></a>00126   <span class="keywordflow">if</span> (0){info=<a class="code" href="group__SDPBasic.html#ga66567faeecc4cb75f7ae3a3eed966bd4" title="Print a data matrix to the screen.">SDPConeViewDataMatrix</a>(sdpcone,0,0);}
<a name="l00127"></a>00127   <span class="comment">/* Diagonal elements must equal 1 */</span>
<a name="l00128"></a>00128   <span class="keywordflow">for</span> (i=0;i&lt;nnodes;i++){
<a name="l00129"></a>00129     info = <a class="code" href="group__DSDPBasic.html#ga7e1b78dc7d7407fcf84e05b9c42fc72c" title="Set the objective vector b in (D).">DSDPSetDualObjective</a>(dsdp,i+1,1.0);CHKERR(info); 
<a name="l00130"></a>00130     info = <a class="code" href="group__DSDPSolution.html#gacf5a2bd7ecb03b319caa22e545ef8e01" title="Set the initial values of variables y in (D).">DSDPSetY0</a>(dsdp,i+1,0.0);CHKERR(info); 
<a name="l00131"></a>00131     info = <a class="code" href="group__SDPBasic.html#gaa6ed45b2539266f04bd4b8401aa89c06" title="Set data matrix  in a sparse format.">SDPConeSetASparseVecMat</a>(sdpcone,0,i+1,nnodes,1.0,0,iptr+i,diag+i,1);CHKERR(info); 
<a name="l00132"></a>00132   }
<a name="l00133"></a>00133 
<a name="l00134"></a>00134   <span class="comment">/* </span>
<a name="l00135"></a>00135 <span class="comment">     For each edge connecting nodes i and j, </span>
<a name="l00136"></a>00136 <span class="comment">     X(i,i)+X(j,j)+X(i,j)+X(j,i)+X(i,n)+X(n,i)+X(j,n)+X(n,j)+X(n,n) = 1</span>
<a name="l00137"></a>00137 <span class="comment">     where nodes i,j numbered 0 ... n-1.</span>
<a name="l00138"></a>00138 <span class="comment">  */</span>
<a name="l00139"></a>00139   <span class="keywordflow">for</span> (i=0; i&lt;edges; i++){
<a name="l00140"></a>00140     info = <a class="code" href="group__SDPData.html#ga0568ca9b863657cf47e431b4ee580194" title="Add data matrix  where v is a sparse vector.">SDPConeAddARankOneMat</a>(sdpcone,0,i+nnodes+1,nnodes,1.0,0,Edge[i].indd,Edge[i].v,3);
<a name="l00141"></a>00141     <span class="keywordflow">if</span> (0==1){info = <a class="code" href="group__SDPBasic.html#ga66567faeecc4cb75f7ae3a3eed966bd4" title="Print a data matrix to the screen.">SDPConeViewDataMatrix</a>(sdpcone,0,i+nnodes+1);CHKERR(info);}
<a name="l00142"></a>00142     info = <a class="code" href="group__DSDPBasic.html#ga7e1b78dc7d7407fcf84e05b9c42fc72c" title="Set the objective vector b in (D).">DSDPSetDualObjective</a>(dsdp,i+nnodes+1,1.0);CHKERR(info); 
<a name="l00143"></a>00143     info = <a class="code" href="group__DSDPSolution.html#gacf5a2bd7ecb03b319caa22e545ef8e01" title="Set the initial values of variables y in (D).">DSDPSetY0</a>(dsdp,i+nnodes+1,0.0);CHKERR(info); 
<a name="l00144"></a>00144   }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146   <span class="comment">/* The initial point y is feasible and near the central path */</span>
<a name="l00147"></a>00147   <span class="comment">/*</span>
<a name="l00148"></a>00148 <span class="comment">  info = DSDPSetR0(dsdp,0);</span>
<a name="l00149"></a>00149 <span class="comment">  */</span>  
<a name="l00150"></a>00150   <span class="keywordflow">return</span>(0);
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 
<a name="l00164"></a><a class="code" href="group__Examples.html#ga19a56f8df210e5a7ba6e0970e5c9187a">00164</a> <span class="keywordtype">int</span> <a class="code" href="group__Examples.html#ga19a56f8df210e5a7ba6e0970e5c9187a" title="Apply a randomized procedure to find feasible stable sets.">StableRandomized</a>(<a class="code" href="structSDPCone__C.html" title="Internal structure for semidefinite cone.">SDPCone</a> sdpcone,<span class="keywordtype">int</span> nodes, <span class="keywordtype">int</span> edges, EdgeMat Edge[]){
<a name="l00165"></a>00165   <span class="keywordtype">int</span> i,j,derror,info,nnodes=nodes+1;
<a name="l00166"></a>00166   <span class="keywordtype">double</span> dd,scal=RAND_MAX,*vv,*tt,*cc,ymin=0;
<a name="l00167"></a>00167   <span class="keywordtype">int</span> e0,e1,e2;
<a name="l00168"></a>00168 
<a name="l00169"></a>00169   vv=(<span class="keywordtype">double</span>*)malloc(nnodes*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00170"></a>00170   tt=(<span class="keywordtype">double</span>*)malloc(nnodes*<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));
<a name="l00171"></a>00171   cc=(<span class="keywordtype">double</span>*)malloc((edges+nnodes+2)*<span class="keyword">sizeof</span>(double));
<a name="l00172"></a>00172   info=<a class="code" href="group__SDPRoutines.html#ga274b127d17d7dec0dc4b0ca499f13e89" title="Compute a factor V such that .">SDPConeComputeXV</a>(sdpcone,0,&amp;derror);
<a name="l00173"></a>00173   <span class="keywordflow">for</span> (i=0;i&lt;nnodes;i++){
<a name="l00174"></a>00174       <span class="keywordflow">for</span> (j=0;j&lt;nnodes;j++){dd = (( rand())/scal - .5); vv[j] = tan(3.1415926*dd);}
<a name="l00175"></a>00175       info=<a class="code" href="group__SDPRoutines.html#ga288158182d952a72534b9c8894407c5b" title="Multiply an array by a factor V such that .">SDPConeXVMultiply</a>(sdpcone,0,vv,tt,nnodes);
<a name="l00176"></a>00176       <span class="keywordflow">for</span> (j=0; j&lt;edges; j++){
<a name="l00177"></a>00177         e0=Edge[j].indd[0];e1=Edge[j].indd[1];e2=Edge[j].indd[2];
<a name="l00178"></a>00178         <span class="keywordflow">if</span> (tt[e0] * tt[e2] &gt; 0 &amp;&amp; tt[e1]*tt[e2] &gt;0){
<a name="l00179"></a>00179           <span class="keywordflow">if</span> ( fabs(tt[e0]-tt[e2]) &gt; fabs(tt[e1]-tt[e2]) ){
<a name="l00180"></a>00180             tt[e0]*=-1;
<a name="l00181"></a>00181           } <span class="keywordflow">else</span> {
<a name="l00182"></a>00182             tt[e1]*=-1;
<a name="l00183"></a>00183           }
<a name="l00184"></a>00184         } 
<a name="l00185"></a>00185       }
<a name="l00186"></a>00186       <span class="keywordflow">for</span> (j=0;j&lt;nnodes;j++){<span class="keywordflow">if</span> (tt[j]&lt;0) tt[j]=-1; <span class="keywordflow">else</span> tt[j]=1;}
<a name="l00187"></a>00187       <span class="keywordflow">for</span> (j=0;j&lt;edges+nodes+1;j++){cc[j]=0;}
<a name="l00188"></a>00188       info=<a class="code" href="group__SDPRoutines.html#ga521bba9ef443933ea8748aa1e7f8d142" title="Compute  for i = 0 through m.">SDPConeAddXVAV</a>(sdpcone,0,tt,nnodes,cc,edges+nnodes+2);
<a name="l00189"></a>00189       <span class="keywordflow">if</span> (cc[0]&lt;ymin) ymin=cc[0];
<a name="l00190"></a>00190   }
<a name="l00191"></a>00191   printf(<span class="stringliteral">&quot;Stable Set Size: %4.0f\n&quot;</span>,-ymin);
<a name="l00192"></a>00192   free(vv); free(tt); free(cc);
<a name="l00193"></a>00193 
<a name="l00194"></a>00194   <span class="keywordflow">return</span>(0);
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196 
<a name="l00197"></a>00197 
<a name="l00198"></a>00198 <span class="preprocessor">#define BUFFERSIZ 100</span>
<a name="l00199"></a>00199 <span class="preprocessor"></span>
<a name="l00200"></a>00200 <span class="preprocessor">#undef __FUNCT__  </span>
<a name="l00201"></a>00201 <span class="preprocessor"></span><span class="preprocessor">#define __FUNCT__ &quot;ParseGraphline&quot;</span>
<a name="l00202"></a>00202 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">int</span> ParseGraphline(<span class="keywordtype">char</span> * thisline,<span class="keywordtype">int</span> *row,<span class="keywordtype">int</span> *col,<span class="keywordtype">double</span> *value, 
<a name="l00203"></a>00203                           <span class="keywordtype">int</span> *gotem){
<a name="l00204"></a>00204 
<a name="l00205"></a>00205   <span class="keywordtype">int</span> temp;
<a name="l00206"></a>00206   <span class="keywordtype">int</span> rtmp,coltmp;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208   rtmp=-1, coltmp=-1, *value=0.0;
<a name="l00209"></a>00209   temp=sscanf(thisline,<span class="stringliteral">&quot;%d %d %lf&quot;</span>,&amp;rtmp,&amp;coltmp,value);
<a name="l00210"></a>00210   <span class="keywordflow">if</span> (temp==3 &amp;&amp; rtmp&gt;0 &amp;&amp; coltmp&gt;0) *gotem=3;
<a name="l00211"></a>00211   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (temp==2 &amp;&amp; rtmp&gt;0 &amp;&amp; coltmp&gt;0){ *value = 1.0; *gotem=3;}
<a name="l00212"></a>00212   <span class="keywordflow">else</span> *gotem=0;
<a name="l00213"></a>00213   *row=rtmp-1; *col=coltmp-1;
<a name="l00214"></a>00214   <span class="keywordflow">if</span> (*gotem &amp;&amp; (*col &lt; 0 || *row &lt; 0)){
<a name="l00215"></a>00215     printf(<span class="stringliteral">&quot;Node Number must be positive.\n, %s\n&quot;</span>,thisline);
<a name="l00216"></a>00216   }
<a name="l00217"></a>00217   <span class="keywordflow">return</span>(0);
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219 
<a name="l00220"></a>00220 <span class="preprocessor">#undef __FUNCT__  </span>
<a name="l00221"></a>00221 <span class="preprocessor"></span><span class="preprocessor">#define __FUNCT__ &quot;ReadGraphFromFile&quot;</span>
<a name="l00222"></a>00222 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">int</span> ReadGraphFromFile(<span class="keywordtype">char</span>* filename,<span class="keywordtype">int</span> *nnodes, <span class="keywordtype">int</span> *nedges, EdgeMat**EE){
<a name="l00223"></a>00223 
<a name="l00224"></a>00224   FILE*fp;
<a name="l00225"></a>00225   <span class="keywordtype">char</span> thisline[BUFFERSIZ]=<span class="stringliteral">&quot;*&quot;</span>;
<a name="l00226"></a>00226   <span class="keywordtype">int</span> i,k=0,line=0,nodes,edges,gotone=3;
<a name="l00227"></a>00227   <span class="keywordtype">int</span> info,row,col;
<a name="l00228"></a>00228   <span class="keywordtype">double</span> value;
<a name="l00229"></a>00229   EdgeMat *E;
<a name="l00230"></a>00230 
<a name="l00231"></a>00231   fp=fopen(filename,<span class="stringliteral">&quot;r&quot;</span>);
<a name="l00232"></a>00232   <span class="keywordflow">if</span> (!fp){ printf(<span class="stringliteral">&quot;Cannot open file %s !&quot;</span>,filename); <span class="keywordflow">return</span>(1); }
<a name="l00233"></a>00233 
<a name="l00234"></a>00234   <span class="keywordflow">while</span>(!feof(fp) &amp;&amp; (thisline[0] == <span class="charliteral">&#39;*&#39;</span> || thisline[0] == <span class="charliteral">&#39;&quot;&#39;</span>) ){
<a name="l00235"></a>00235     fgets(thisline,BUFFERSIZ,fp); line++; }
<a name="l00236"></a>00236 
<a name="l00237"></a>00237   <span class="keywordflow">if</span> (sscanf(thisline,<span class="stringliteral">&quot;%d %d&quot;</span>,&amp;nodes, &amp;edges)!=2){
<a name="l00238"></a>00238     printf(<span class="stringliteral">&quot;First line must contain the number of nodes and number of edges\n&quot;</span>);
<a name="l00239"></a>00239     <span class="keywordflow">return</span> 1;
<a name="l00240"></a>00240   }
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   E=(EdgeMat*)malloc(edges*<span class="keyword">sizeof</span>(EdgeMat)); *EE=E;
<a name="l00243"></a>00243   <span class="keywordflow">for</span> (i=0; i&lt;edges; i++){ 
<a name="l00244"></a>00244     E[i].v[0]=0; E[i].v[1]=0; E[i].v[2]=0; 
<a name="l00245"></a>00245     E[i].indd[0]=0; E[i].indd[1]=0; E[i].indd[2]=0; 
<a name="l00246"></a>00246   }
<a name="l00247"></a>00247 
<a name="l00248"></a>00248   <span class="keywordflow">while</span>(!feof(fp) &amp;&amp; gotone){
<a name="l00249"></a>00249     thisline[0]=<span class="charliteral">&#39;\0&#39;</span>;
<a name="l00250"></a>00250     fgets(thisline,BUFFERSIZ,fp); line++;
<a name="l00251"></a>00251     info = ParseGraphline(thisline,&amp;row,&amp;col,&amp;value,&amp;gotone);
<a name="l00252"></a>00252     <span class="keywordflow">if</span> (gotone &amp;&amp; k&lt;edges &amp;&amp; 
<a name="l00253"></a>00253         col &lt; nodes &amp;&amp; row &lt; nodes &amp;&amp; col &gt;= 0 &amp;&amp; row &gt;= 0){
<a name="l00254"></a>00254       <span class="keywordflow">if</span> (row &gt; col){i=row;row=col;col=i;}
<a name="l00255"></a>00255       <span class="keywordflow">if</span> (row == col){}
<a name="l00256"></a>00256       <span class="keywordflow">else</span> {
<a name="l00257"></a>00257         E[k].indd[0]=row; E[k].indd[1]=col; E[k].indd[2]=nodes; 
<a name="l00258"></a>00258         E[k].v[0]=1.0;    E[k].v[1]=1.0;    E[k].v[2]=1.0; 
<a name="l00259"></a>00259         k++;
<a name="l00260"></a>00260       }
<a name="l00261"></a>00261     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (gotone &amp;&amp;  k&gt;=edges) {
<a name="l00262"></a>00262       printf(<span class="stringliteral">&quot;To many edges in file.\nLine %d, %s\n&quot;</span>,line,thisline);
<a name="l00263"></a>00263       <span class="keywordflow">return</span> 1;
<a name="l00264"></a>00264     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (gotone&amp;&amp;(col &gt;= nodes || row &gt;= nodes || col &lt; 0 || row &lt; 0)){
<a name="l00265"></a>00265       printf(<span class="stringliteral">&quot;Invalid node number.\nLine %d, %s\n&quot;</span>,line,thisline);
<a name="l00266"></a>00266       <span class="keywordflow">return</span> 1;
<a name="l00267"></a>00267     }
<a name="l00268"></a>00268   }
<a name="l00269"></a>00269 
<a name="l00270"></a>00270   *nnodes=nodes; *nedges=k;
<a name="l00271"></a>00271                                                  
<a name="l00272"></a>00272   <span class="keywordflow">return</span> 0;
<a name="l00273"></a>00273 }
<a name="l00274"></a>00274 
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Jun 8 2011 for DSDP by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>