public override double determineObjectiveValue(out Coords[] partition) { int[] extendedIndicesArray = determineExtendedIndicesArray(); fillObjectiveValueArray(); bool hasEnoughBins = (bool)hasEnoughBinsArray.GetValue(extendedIndicesArray); double objectiveValue = (double)objectiveValueArray.GetValue(extendedIndicesArray); if (!hasEnoughBins) { throw new NotEnoughBinsException(); } objectiveValue = objectiveValue / (double)serverNO; partition = (Coords[])partitionArray.GetValue(extendedIndicesArray); diffSum = determineCurrentDiffSum(partition); double measureOfKNN = kNNMeasure.computeMeasure(partition); Console.WriteLine("k-NN measure of the partition: {0}", measureOfKNN); double measureOfRange = rangeMeasure.averageAllMeasures(partition); Console.WriteLine("Range measure of the partition: {0}", measureOfRange); double measureOfLB = lbMeasure.computeMeasure(partition); Console.WriteLine("Load balancing measure of the partition: {0}", measureOfLB); double measureOfBox = boxMeasure.averageAllMeasures(partition); Console.WriteLine("Box measure of the partition: {0}", measureOfBox); return objectiveValue; }
protected double determineCurrentDiffSum(Coords[] partition) { double diffSum = 0.0; for (int idx = 0; idx < partition.Length; idx++) { diffSum += partition[idx].differenceFromDelta(delta); } return diffSum; }
private void fillObjectiveValueForSplitComponent(int[] extendedIndicesArray, int[] indicesArray, ref Coords[] partition, ref double objectiveValue, int splitNO, int componentInSplitDim, int splitDimIdx) { int[] firstPartIndicesArray, secondPartIndicesArray; int[] firstPartExtendedIndicesArray = new int[2 * spaceDimension + 1]; int[] secondPartExtendedIndicesArray = new int[2 * spaceDimension + 1]; Coords[] firstPartPartition, secondPartPartition; bool hasEnoughBinsForFirstPart, hasEnoughBinsForSecondPart; transformator.splitIndicesArrays(spaceDimension, splitDimIdx, indicesArray, componentInSplitDim, out firstPartIndicesArray, out secondPartIndicesArray); for (int firstSplitNO = 0; firstSplitNO <= splitNO - 1; firstSplitNO++) { int secondSplitNO = (splitNO - 1) - firstSplitNO; firstPartIndicesArray.CopyTo(firstPartExtendedIndicesArray, 1); firstPartExtendedIndicesArray[0] = firstSplitNO; secondPartIndicesArray.CopyTo(secondPartExtendedIndicesArray, 1); secondPartExtendedIndicesArray[0] = secondSplitNO; double objectiveValueForFirstPart = innerDetermineObjectiveValue(firstPartExtendedIndicesArray, out firstPartPartition, out hasEnoughBinsForFirstPart); double objectiveValueForSecondPart = innerDetermineObjectiveValue(secondPartExtendedIndicesArray, out secondPartPartition, out hasEnoughBinsForSecondPart); double currentObjectiveValue = 0.0; // If the objective value of a part of the current region is zero // then the current objective value is zero because this case is applied // when a part of the current region has zero heft which would belong to a server. if ((objectiveValueForFirstPart != 0.0) && (objectiveValueForSecondPart != 0.0)) { currentObjectiveValue = objectiveValueForFirstPart + objectiveValueForSecondPart; } if ((currentObjectiveValue >= objectiveValue) && hasEnoughBinsForFirstPart && hasEnoughBinsForSecondPart) { objectiveValue = currentObjectiveValue; partition = new Coords[splitNO + 1]; setPartitionByParts(extendedIndicesArray, partition, firstPartPartition, secondPartPartition); } } }
private double fillObjectiveValueArray(int[] extendedIndicesArray, out Coords[] partition, out bool hasEnoughBins) { double objectiveValue = 0.0; int[] indicesArray = transformator.determineIndicesArray(spaceDimension, extendedIndicesArray); int splitNO = extendedIndicesArray[0]; if (splitNO == 0) { hasEnoughBins = true; partition = fillObjectiveValueWhenSplitNOIsZero(extendedIndicesArray, ref objectiveValue, indicesArray); } else { hasEnoughBins = transformator.validateRegionHasEnoughBins(spaceDimension, indicesArray, splitNO); if (hasEnoughBins) objectiveValue = fillObjectiveValueWhenSplitNOIsLargerThenZero(extendedIndicesArray, indicesArray, out partition); else partition = null; } objectiveValueArray.SetValue(objectiveValue, extendedIndicesArray); hasEnoughBinsArray.SetValue(hasEnoughBins, extendedIndicesArray); return objectiveValue; }
private void getValuesFromParts(int[] firstPartIndicesArray, int[] secondPartIndicesArray, int firstSplitNO, int secondSplitNO, out double objectiveValueForFirstPart, out Coords[] firstPartPartition, out bool hasEnoughBinsForFirstPart, out double objectiveValueForSecondPart, out Coords[] secondPartPartition, out bool hasEnoughBinsForSecondPart) { int[] firstPartExtendedIndicesArray = new int[2 * spaceDimension + 1]; int[] secondPartExtendedIndicesArray = new int[2 * spaceDimension + 1]; firstPartIndicesArray.CopyTo(firstPartExtendedIndicesArray, 1); firstPartExtendedIndicesArray[0] = firstSplitNO; secondPartIndicesArray.CopyTo(secondPartExtendedIndicesArray, 1); secondPartExtendedIndicesArray[0] = secondSplitNO; objectiveValueForFirstPart = (double)objectiveValueArray.GetValue(firstPartExtendedIndicesArray); firstPartPartition = (Coords[])partitionArray.GetValue(firstPartExtendedIndicesArray); hasEnoughBinsForFirstPart = (bool)hasEnoughBinsArray.GetValue(firstPartExtendedIndicesArray); objectiveValueForSecondPart = (double)objectiveValueArray.GetValue(secondPartExtendedIndicesArray); secondPartPartition = (Coords[])partitionArray.GetValue(secondPartExtendedIndicesArray); hasEnoughBinsForSecondPart = (bool)hasEnoughBinsArray.GetValue(secondPartExtendedIndicesArray); }
private double fillObjectiveValueWhenSplitNOIsZero(int[] extendedIndicesArray, double objectiveValue, int[] indicesArray) { Coords[] partition; int heftOfRegion = (int)heftArray.GetValue(indicesArray); Coords coords = new Coords { ExtendedIndicesArray = extendedIndicesArray, HeftOfRegion = heftOfRegion }; partition = new Coords[] { coords }; partitionArray.SetValue(partition, extendedIndicesArray); // If the heft of the current region is zero the objective value is zero // because region with zero heft should not belong to a server. if (heftOfRegion != 0) objectiveValue = kNNMeasCoeff * kNNMeasure.computeMeasureForRegion(coords) + lbMeasCoeff * lbMeasure.computeMeasureForRegion(coords); return objectiveValue; }
private double fillObjectiveValueForFixedSplitNOComposition(int[] extendedIndicesArray, double objectiveValue, int splitNO, int[] firstPartIndicesArray, int[] secondPartIndicesArray, int firstSplitNO, int secondSplitNO) { double objectiveValueForFirstPart, objectiveValueForSecondPart; Coords[] firstPartPartition, secondPartPartition; bool hasEnoughBinsForFirstPart, hasEnoughBinsForSecondPart; getValuesFromParts(firstPartIndicesArray, secondPartIndicesArray, firstSplitNO, secondSplitNO, out objectiveValueForFirstPart, out firstPartPartition, out hasEnoughBinsForFirstPart, out objectiveValueForSecondPart, out secondPartPartition, out hasEnoughBinsForSecondPart); double currentObjectiveValue = 0.0; // If the objective value of a part of the current region is zero // then the current objective value is zero because this case is applied // when a part of the current region has zero heft which would belong to a server. if ((objectiveValueForFirstPart != 0.0) && (objectiveValueForSecondPart != 0.0)) { currentObjectiveValue = objectiveValueForFirstPart + objectiveValueForSecondPart; } if ((currentObjectiveValue >= objectiveValue) && hasEnoughBinsForFirstPart && hasEnoughBinsForSecondPart) { objectiveValue = currentObjectiveValue; Coords[] partition = new Coords[splitNO + 1]; setPartitionByParts(extendedIndicesArray, partition, firstPartPartition, secondPartPartition); } return objectiveValue; }
private static void writeOutCellsToServers(int histogramResolution, int serverNO, Coords[] partition) { StringBuilder strBldr = new StringBuilder(); for (int serverIdx = 0; serverIdx < serverNO; serverIdx++) { int[] extendedIndicesArray = partition[serverIdx].ExtendedIndicesArray; for (int x = extendedIndicesArray[1]; x <= extendedIndicesArray[2]; x++) { for (int y = extendedIndicesArray[3]; y <= extendedIndicesArray[4]; y++) { int cellIdx = x * histogramResolution + y; strBldr.Append(cellIdx); if ((x != extendedIndicesArray[2]) || (y != extendedIndicesArray[4])) { strBldr.Append(" "); } } } strBldr.AppendLine(); } string serversOutput = @"c:\temp\data\hier_tiling\cells_to_servers.dat"; System.IO.File.WriteAllText(serversOutput, strBldr.ToString()); }
private static void writeOutTiles(int serverNO, int spaceDimension, Coords[] partition) { StringBuilder strBldr = new StringBuilder(); for (int idx = 0; idx < serverNO; idx++) { partition[idx].printCoords(spaceDimension, idx + 1); partition[idx].writeToStringBuilder(spaceDimension, strBldr); } string tilesOutput = @"c:\temp\data\hier_tiling\tiles.dat"; System.IO.File.WriteAllText(tilesOutput, strBldr.ToString()); }
private static void writeOutServers(int serverNO, Coords[] partition) { StringBuilder strBldr = new StringBuilder(); for (int tileIdx = 0; tileIdx < serverNO; tileIdx++) { strBldr.Append(partition[tileIdx].HeftOfRegion).Append(" " + tileIdx); strBldr.AppendLine(); } string serversOutput = @"c:\temp\data\hier_tiling\servers.dat"; System.IO.File.WriteAllText(serversOutput, strBldr.ToString()); }
protected void setPartitionByParts(int[] extendedIndicesArray, Coords[] partition, Coords[] firstPartPartition, Coords[] secondPartPartition) { firstPartPartition.CopyTo(partition, 0); secondPartPartition.CopyTo(partition, firstPartPartition.Length); partitionArray.SetValue(partition, extendedIndicesArray); }
public abstract double determineObjectiveValue(out Coords[] partition);
private double innerDetermineObjectiveValue(int[] extendedIndicesArray, out Coords[] partition, out bool hasEnoughBins) { double objectiveValue; double currentObjectiveValue = (double)objectiveValueArray.GetValue(extendedIndicesArray); if (currentObjectiveValue >= 0) { objectiveValue = currentObjectiveValue; partition = (Coords[])partitionArray.GetValue(extendedIndicesArray); hasEnoughBins = (bool)hasEnoughBinsArray.GetValue(extendedIndicesArray); } else { objectiveValue = fillObjectiveValueArray(extendedIndicesArray, out partition, out hasEnoughBins); } return objectiveValue; }
private double fillObjectiveValueWhenSplitNOIsLargerThenZero(int[] extendedIndicesArray, int[] indicesArray, out Coords[] partition) { double objectiveValue = 0.0; int splitNO = extendedIndicesArray[0]; partition = (Coords[])partitionArray.GetValue(extendedIndicesArray); for (int splitDimIdx = 0; splitDimIdx < spaceDimension; splitDimIdx++) { for (int componentInSplitDim = indicesArray[2 * splitDimIdx]; componentInSplitDim < indicesArray[2 * splitDimIdx + 1]; componentInSplitDim++) { fillObjectiveValueForSplitComponent(extendedIndicesArray, indicesArray, ref partition, ref objectiveValue, splitNO, componentInSplitDim, splitDimIdx); } } return objectiveValue; }