Bug fixes in min cost flow files.
Use enum type instead of static constants in NetworkSimplex to avoid
linker errors.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_RANDOM_H
20 #define LEMON_RANDOM_H
26 #include <lemon/dim2.h>
30 ///\brief Measure a Distribution
32 ///\todo Needs lot more docs
38 ///Measure a distribution
41 std::vector<int> _dist;
47 Dist(double lo,double up,int gr,bool cut=true)
48 : _dist(gr,0),_lo(lo),_up(up),_count(0),_cut(cut) {}
50 void operator()(double v)
54 _dist[int((v-_lo)/(_up-_lo)*_dist.size())]++;
57 _dist[std::max(0,std::min(int(_dist.size())-1,
58 int((v-_lo)/(_up-_lo)*_dist.size())
64 void dump(std::ostream& os=std::cout)
66 for(int i=0;i<_dist.size();i++)
67 os << _lo+(i+0.5)*(_up-_lo)/_dist.size() << ' '
68 << double(_dist[i])/_count << std::endl;
71 void dump(const std::string& file_name)
73 dump(std::ofstream(file_name.c_str()));
77 ///Measure a two dimensional distribution
81 typedef dim2::Point<double> Point;
83 std::vector<int> _dist;
90 Dist2(Point a,Point b,int gr,bool cut=true) :
91 _dist(gr*gr,0),_gr(gr),
92 _lo(a),_up(b),_count(0),_cut(cut) {}
94 Dist2(double lox,double upx,double loy,double upy,int gr,bool cut=true) :
95 _dist(gr*gr,0),_gr(gr),
96 _lo(Point(lox,loy)),_up(Point(upx,upy)),_count(0),_cut(cut) {}
98 void operator()(Point v)
102 if(v.x>=_lo.x && v.x<_up.x && v.y>=_lo.y && v.y<_up.y)
103 _dist[int((v.x-_lo.x)/(_up.x-_lo.x)*_gr)*_gr+
104 int((v.y-_lo.y)/(_up.y-_lo.y)*_gr)]++;
107 _dist[std::max(0,std::min(_gr-1,
108 int((v.x-_lo.x)/(_up.x-_lo.x)*_gr)
110 std::max(0,std::min(_gr-1,
111 int((v.y-_lo.y)/(_up.y-_lo.y)*_gr)
118 void dump(std::ostream& os=std::cout)
120 for(int i=0;i<_gr;i++)
122 for(int j=0;j<_gr;j++)
123 os << _lo.x+(i+0.5)*(_up.x-_lo.x)/_gr << ' '
124 << _lo.y+(j+0.5)*(_up.y-_lo.y)/_gr << ' '
125 << double(_dist[i*_gr+j])/_count << std::endl;
130 void dump(const std::string& file_name)
132 dump(std::ofstream(file_name.c_str()));