Recover exercise 2 from last week: flow.h,
flow.cc.
Download the new flow2.h (which #include flow.h),
and rename flow.cc as flow2.cc, and modify it to fit flow2.h.
#ifndef __FLOW2_H
#define __FLOW2_H
#include "flow.h"
// Like BestFlow() in flow.h, but we add a penalty cost for "filling" the
// backbone arcs too much: if the utilization ratio U of an arc (U is in
// [0,1], U=0 means unused, U=1 means fully used, at capacity limit) is
// greater than some constant x (for example x=0.9), we'll pay a penalty
// cost proportional to (U - x).
//
// We still want to maximize profit, but taking the costs into account (as
// negative profits).
//
// Example:
// - A backbone with 4 arcs of capacities 1000, 300, 500, 100.
// - A solution where the sums of flows on these 4 arcs are: 840, 300, 470, 90
// (those are the 'U' in the fomula above).
// If max_free_utilization_ratio=0.9 (this is the 'x' in the formula above),
// the arcs that are "over-utilized" are the second and third one. The first
// one is below the threshold, and the last is exactly at the threshold.
// The over-utilization coefficients of these arcs are: 0, 0.1, 0.04, 0
// (these are the (U - x) in the formula above)).
// If penalt_cost=100, the cost of this over-utilization is:
// 0.1 * penalty_cost + 0.04 * penalty_cost = 14.
//
// HINTS:
// One can mimic and even replace the original capacity constraints from
// last week's flow.cc by introducing the "over-utilization" variables, and
// adding them to the capacity constraints.
vector<FlowOnArc> BestFlow2(int num_nodes, const vector<BackboneArc>& backbone,
const vector<FlowDemand>& demands,
double max_free_utilization_ratio,
double penalty_cost);
#endif // __FLOW2_H
Test: wget ‐‐no-cache http://fabien.viger.free.fr/oc/td7/test.tar.gz
tar xf test.tar.gz
make flow2
TO SUBMIT: flow2.cc (do not modify the .h files!)