<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
<MAN>
  <LANGUAGE>eng</LANGUAGE>
  <TITLE>min_qcost_flow</TITLE>
  <TYPE>Scilab function</TYPE>
  <DATE>September 1995</DATE>
  <SHORT_DESCRIPTION name="min_qcost_flow"> minimum quadratic cost flow</SHORT_DESCRIPTION>
  <CALLING_SEQUENCE>
    <CALLING_SEQUENCE_ITEM>[c,phi,flag] = min_qcost_flow(eps,g)  </CALLING_SEQUENCE_ITEM>
  </CALLING_SEQUENCE>
  <PARAM>
    <PARAM_INDENT>
      <PARAM_ITEM>
        <PARAM_NAME>eps</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: scalar, precision</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>g</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: graph list</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>c</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: value of cost</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>phi</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: row vector of the value of flow on the arcs</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>flag</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: feasible problem flag (0 or 1)</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
    </PARAM_INDENT>
  </PARAM>
  <DESCRIPTION>
    <P><VERB>min_qcost_flow</VERB> computes the minimum quadratic cost flow in the network 
    <VERB>g</VERB>. It returns the total cost of the flows on the arcs <VERB>c</VERB> and
    the row vector of the flows on the arcs <VERB>phi</VERB>. <VERB>eps</VERB> is the precision
    of the iterative algorithm. If the problem is not feasible (impossible to 
    find a compatible flow for instance), <VERB>flag</VERB> is equal to 0, otherwise it 
    is equal to 1.</P>
    <P>
    The bounds of the flow are given by the elements <VERB>edge_min_cap</VERB> and
    <VERB>edge_max_cap</VERB> of the graph list. 
    The value of the maximum capacity must be greater than or equal to the 
    value of the minimum capacity.
    If the value of <VERB>edge_min_cap</VERB> or <VERB>edge_max_cap</VERB> is not given (empty
    row vector <VERB>[]</VERB>), it is assumed to be equal to 0 on each edge.</P>
    <P>
    The costs on the edges are given by the elements <VERB>edge_q_orig</VERB> and
    <VERB>edge_q_weight</VERB> of the graph list. The cost on arc <VERB>u</VERB> is given by:</P>
    <P>
      <VERB>(1/2)*edge_q_weight[u](phi[u]-edge_q_orig[u])^2</VERB>
    </P>
    <P>
    The costs must be non negative.
    If the value of <VERB>edge_q_orig</VERB> or <VERB>edge_q_weight</VERB> is not given (empty 
    row vector <VERB>[]</VERB>), it is assumed to be equal to 0 on each edge.</P>
    <P>
    This function uses an algorithm due to M. Minoux.</P>
  </DESCRIPTION>
  <EXAMPLE>
<![CDATA[
ta=[1 1 2 2 2 3 4 4 5 6 6 6 7 7 7 8 9 10 12 12 13 13 13 14 15 14 9 11 10 1 8];
he=[2 6 3 4 5 1 3 5 1 7 10 11 5 8 9 5 8 11 10 11 9 11 15 13 14 4 6 9 1 12 14];
g=make_graph('foo',1,15,ta,he);
g('node_x')=[194 191 106 194 296 305 305 418 422 432 552 550 549 416 548];
g('node_y')=[56 221 316 318 316 143 214 321 217 126 215 80 330 437 439];
show_graph(g);
g1=g; ma=arc_number(g1);
rand('uniform');
while %T then
  g1('edge_min_cap')=round(5*rand(1,ma));
  g1('edge_max_cap')=round(20*rand(1,ma))+30*ones(1,ma);
  g1('edge_q_orig')=0*ones(1,ma);
  g1('edge_q_weight')=ones(1,ma);
  [c,phi,flag]=min_qcost_flow(0.001,g1);
 if flag==1 then break; end;
end;
x_message(['The cost is: '+string(c);
          'Showing the flow on the arcs']);
ii=find(phi<>0); edgecolor=phi; edgecolor(ii)=11*ones(ii);
g1('edge_color')=edgecolor;
edgefontsize=8*ones(1,ma); edgefontsize(ii)=18*ones(ii);
g1('edge_font_size')=edgefontsize;
g1('edge_label')=string(phi);
show_graph(g1);
 ]]>
  </EXAMPLE>
  <SEE_ALSO>
    <SEE_ALSO_ITEM>
      <LINK>min_lcost_cflow</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>min_lcost_flow1</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>min_lcost_flow2</LINK>
    </SEE_ALSO_ITEM>
  </SEE_ALSO>
</MAN>
