Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <oned/greedy_bisect.hpp>
00038
00039 template <typename T, typename Pr>
00040 T oned::GreedyBisection<T,Pr>::greedy_bisection(int procCount,
00041 const Pr& prefixSumArray,
00042 int length, int *cutIndexes,
00043 T )
00044 {
00045 T v = greedy_bisect_internal(procCount, prefixSumArray, length, cutIndexes);
00046 return v;
00047 }
00048
00049
00050 template <typename T, typename Pr>
00051 T oned::GreedyBisection<T,Pr>::greedy_bisect_internal(int procCount,
00052 const Pr& prefixSumArray,
00053 int length, int *cutIndexes)
00054 {
00055 std::priority_queue<HeapElement, std::vector<HeapElement>,
00056 HeapElementCompare> heap;
00057
00058 HeapElement model;
00059 int hsize = 1;
00060 T bottleneck = -1;
00061
00062 model.weight = prefixSumArray[length - 1];
00063 model.low = 1;
00064 model.high = length - 1;
00065
00066 heap.push(model);
00067
00068 while(hsize != procCount)
00069 {
00070 int cutPoint=0;
00071
00072 HeapElement out = heap.top();
00073 heap.pop();
00074
00075
00076 assert (out.low > 0);
00077 assert (out.high <= length - 1);
00078
00079 cutPoint = RecursiveBisection<T,Pr>::findEvenCut(prefixSumArray, out.low, out.high, 1, 1);
00080 assert (cutPoint >= out.low);
00081 assert (cutPoint <= out.high);
00082
00083 model.weight = prefixSumArray[cutPoint] - prefixSumArray[out.low-1];
00084 model.low = out.low;
00085 model.high = cutPoint;
00086
00087
00088 heap.push(model);
00089
00090 out.weight = prefixSumArray[out.high] - prefixSumArray[cutPoint];
00091 out.low = cutPoint + 1;
00092
00093 heap.push(out);
00094
00095 hsize++;
00096 }
00097
00098 {
00099 int i = 0;
00100 int remove=0;
00101
00102 while (!heap.empty())
00103 {
00104 HeapElement out;
00105
00106 out=heap.top();
00107 heap.pop();
00108
00109 assert (out.high <= length-1);
00110 assert (out.high >= 0);
00111 assert (out.low <= length-1);
00112 assert (out.low >= 0);
00113 assert (out.low <= out.high);
00114
00115 if(out.weight > bottleneck)
00116 bottleneck = out.weight;
00117 if (!remove && out.high == length-1)
00118 {
00119 remove = 1;
00120 }
00121 else
00122 {
00123 cutIndexes[i] = out.high;
00124 i++;
00125 }
00126 }
00127 }
00128
00129 std::sort(cutIndexes, cutIndexes+procCount-1);
00130
00131
00132 return bottleneck;
00133 }
00134
00135
00136
00137