mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
feat: fix planning bug
This commit is contained in:
parent
a794bd3af4
commit
2384f6cc59
@ -3,9 +3,9 @@ package org.bdware.sc.crdt.planning;
|
|||||||
public class PlanningTest {
|
public class PlanningTest {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
final int nodeIdsCount = 1800;
|
final int nodeIdsCount = 1000;
|
||||||
final int writerCount = 1000;
|
final int writerCount = 500;
|
||||||
final int readerCount = 1000;
|
final int readerCount = 500;
|
||||||
String[] nodeIds = new String[nodeIdsCount];
|
String[] nodeIds = new String[nodeIdsCount];
|
||||||
int[] writers = new int[writerCount];
|
int[] writers = new int[writerCount];
|
||||||
int[] readers = new int[readerCount];
|
int[] readers = new int[readerCount];
|
||||||
@ -18,15 +18,18 @@ public class PlanningTest {
|
|||||||
readers[i - nodeIdsCount + readerCount] = i;
|
readers[i - nodeIdsCount + readerCount] = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long maxDelay = 60;
|
long maxDelay = 300;
|
||||||
int bandwidthUpload = 100 * 1024 * 1024;
|
int bandwidthUpload = 30;
|
||||||
int bandwidthDownload = 100 * 1024 * 1024;
|
int bandwidthDownload = 30;
|
||||||
int datasize = 10 * 1024;
|
int datasize = 10;
|
||||||
double domainSize = 100 * datasize;
|
double domainSize = 100 * datasize;
|
||||||
|
|
||||||
PlanningWith0Expansivity planning0 = new PlanningWith0Expansivity(nodeIds, writers, readers, maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
PlanningWith0Expansivity planning0 = new PlanningWith0Expansivity(nodeIds, writers, readers,
|
||||||
PlanningWithkExpansivity planningK = new PlanningWithkExpansivity(nodeIds, writers, readers, maxDelay, bandwidthDownload, bandwidthUpload, datasize, domainSize);
|
maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
||||||
PlanningWith1Expansivity planning1 = new PlanningWith1Expansivity(nodeIds, writers, readers, maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
PlanningWithkExpansivity planningK = new PlanningWithkExpansivity(nodeIds, writers, readers,
|
||||||
|
maxDelay, bandwidthDownload, bandwidthUpload, datasize, domainSize);
|
||||||
|
PlanningWith1Expansivity planning1 = new PlanningWith1Expansivity(nodeIds, writers, readers,
|
||||||
|
maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
planning0.adjustAndCalc();
|
planning0.adjustAndCalc();
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package org.bdware.sc.crdt.planning;
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
public class PlanningWith0Expansivity extends SharableNetworkPlanning {
|
public class PlanningWith0Expansivity extends SharableNetworkPlanning {
|
||||||
public PlanningWith0Expansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay, int bandwidthDownload, int bandwidthUpload, int dataSize) {
|
public PlanningWith0Expansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay,
|
||||||
|
int bandwidthDownload, int bandwidthUpload, int dataSize) {
|
||||||
this.nodeIds = nodeIds;
|
this.nodeIds = nodeIds;
|
||||||
this.writers = writers;
|
this.writers = writers;
|
||||||
this.readers = readers;
|
this.readers = readers;
|
||||||
@ -14,12 +15,15 @@ public class PlanningWith0Expansivity extends SharableNetworkPlanning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean writerTreeConstraint() {
|
public boolean writerTreeConstraint() {
|
||||||
double common = frequencySyncW * dataSize;
|
if (frequencySyncW > 0) {
|
||||||
// 非叶子节点下载带宽
|
double common = frequencySyncW * dataSize;
|
||||||
boolean result1 = bandwidthDownload >= common * treeDegreeW;
|
// 非叶子节点下载带宽
|
||||||
// 非根节点上行带宽
|
boolean result1 = bandwidthDownload >= common * treeDegreeW;
|
||||||
boolean result2 = bandwidthUpload >= common;
|
// 非根节点上行带宽
|
||||||
return result1 && result2;
|
boolean result2 = bandwidthUpload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean writer2ReaderConstraint() {
|
public boolean writer2ReaderConstraint() {
|
||||||
@ -32,79 +36,35 @@ public class PlanningWith0Expansivity extends SharableNetworkPlanning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean readerTreeConstraint() {
|
public boolean readerTreeConstraint() {
|
||||||
double common = frequencySyncR * dataSize;
|
if (frequencySyncR > 0) {
|
||||||
// Reader非叶子节点上行带宽
|
double common = frequencySyncR * dataSize;
|
||||||
boolean result1 = bandwidthUpload >= common * rootCountR;
|
// Reader非叶子节点上行带宽
|
||||||
// Reader非根节点下载带宽
|
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
||||||
boolean result2 = bandwidthDownload >= common;
|
// Reader非根节点下载带宽
|
||||||
return result1 && result2;
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calcOptimizedResult() {
|
public void calcOptimizedResult() {
|
||||||
double a = totalCountW - rootCountW;
|
double a = (treeHeightW - 1) * (totalCountW - rootCountW);
|
||||||
double b = rootCountR * rootCountW;
|
double b = rootCountR * rootCountW;
|
||||||
double c = totalCountR - rootCountR;
|
double c = (treeHeightR - 1) * (totalCountR - rootCountR);
|
||||||
|
|
||||||
|
double A = Math.sqrt(a);
|
||||||
double A = Math.sqrt(a * (treeHeightW - 1));
|
|
||||||
double B = Math.sqrt(b);
|
double B = Math.sqrt(b);
|
||||||
double C = Math.sqrt(c * (treeHeightR - 1));
|
double C = Math.sqrt(c);
|
||||||
|
|
||||||
wDelay = (long) (maxDelay * (A / (A + B + C)));
|
wDelay = (long) (maxDelay * (A / (A + B + C)));
|
||||||
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
|
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
|
||||||
rDelay = (long) (maxDelay * (C / (A + B + C)));
|
rDelay = (long) (maxDelay * (C / (A + B + C)));
|
||||||
|
|
||||||
frequencySyncW = (treeHeightW - 1) / wDelay;
|
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
|
||||||
frequencySyncR = (treeHeightR - 1) / rDelay;
|
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
|
||||||
frequencySyncWR = 1.0 / w2rDelay;
|
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
|
||||||
|
|
||||||
totalData = (long) (maxDelay * dataSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
totalData = (long) (dataSize
|
||||||
}
|
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
String[] nodeIds = new String[1500];
|
|
||||||
int[] writers = new int[1000];
|
|
||||||
int[] readers = new int[1000];
|
|
||||||
long maxDelay = 60;
|
|
||||||
int bandwidthUpload = 10 * 1024 * 1024;
|
|
||||||
int bandwidthDownload = 10 * 1024 * 1024;
|
|
||||||
int datasize = 10 * 1024;
|
|
||||||
|
|
||||||
PlanningWith0Expansivity planning = new PlanningWith0Expansivity(nodeIds, writers, readers, maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
|
||||||
|
|
||||||
long minTotalData = Long.MAX_VALUE;
|
|
||||||
String result = "";
|
|
||||||
for (int rootCountW = 1; rootCountW <= writers.length; ++rootCountW) {
|
|
||||||
for (int treeDegreeW = 2; treeDegreeW <= writers.length / rootCountW - 1; ++treeDegreeW) {
|
|
||||||
planning.adjustWriterTree(rootCountW, treeDegreeW);
|
|
||||||
for (int rootCountR = 1; rootCountR <= readers.length; ++rootCountR) {
|
|
||||||
for (int treeDegreeR = 2; treeDegreeR <= readers.length / rootCountR - 1; ++treeDegreeR) {
|
|
||||||
planning.adjustReaderTree(rootCountR, treeDegreeR);
|
|
||||||
planning.calcOptimizedResult();
|
|
||||||
if (!planning.readerTreeConstraint()) {
|
|
||||||
//System.out.println("reader");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!planning.writerTreeConstraint()) {
|
|
||||||
//System.out.println("writer");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!planning.writer2ReaderConstraint()) {
|
|
||||||
//System.out.println("writer2Reader");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (minTotalData > planning.totalData) {
|
|
||||||
minTotalData = planning.totalData;
|
|
||||||
result = planning.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println(minTotalData);
|
|
||||||
System.out.println(result);
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
System.out.println("took " + (end - start));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package org.bdware.sc.crdt.planning;
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
public class PlanningWith1Expansivity extends SharableNetworkPlanning {
|
public class PlanningWith1Expansivity extends SharableNetworkPlanning {
|
||||||
public PlanningWith1Expansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay, int bandwidthDownload, int bandwidthUpload, int dataSize) {
|
public PlanningWith1Expansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay,
|
||||||
|
int bandwidthDownload, int bandwidthUpload, int dataSize) {
|
||||||
this.nodeIds = nodeIds;
|
this.nodeIds = nodeIds;
|
||||||
this.writers = writers;
|
this.writers = writers;
|
||||||
this.readers = readers;
|
this.readers = readers;
|
||||||
@ -14,12 +15,15 @@ public class PlanningWith1Expansivity extends SharableNetworkPlanning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean writerTreeConstraint() {
|
public boolean writerTreeConstraint() {
|
||||||
double common = frequencySyncW * (treeNodeCountW - 1) * dataSize;
|
if (frequencySyncW > 0) {
|
||||||
// 非叶子节点下载带宽
|
double common = frequencySyncW * (treeNodeCountW - 1) * dataSize;
|
||||||
boolean result1 = bandwidthDownload >= common;
|
// 非叶子节点下载带宽
|
||||||
// 非根节点上行带宽
|
boolean result1 = bandwidthDownload >= common;
|
||||||
boolean result2 = bandwidthUpload >= common / treeDegreeW;
|
// 非根节点上行带宽
|
||||||
return result1 && result2;
|
boolean result2 = bandwidthUpload >= common / treeDegreeW;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean writer2ReaderConstraint() {
|
public boolean writer2ReaderConstraint() {
|
||||||
@ -32,79 +36,47 @@ public class PlanningWith1Expansivity extends SharableNetworkPlanning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean readerTreeConstraint() {
|
public boolean readerTreeConstraint() {
|
||||||
double common = frequencySyncR * totalCountW * dataSize;
|
if (frequencySyncR > 0) {
|
||||||
// Reader非叶子节点上行带宽
|
double common = frequencySyncR * totalCountW * dataSize;
|
||||||
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
// Reader非叶子节点上行带宽
|
||||||
// Reader非根节点下载带宽
|
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
||||||
boolean result2 = bandwidthDownload >= common;
|
// Reader非根节点下载带宽
|
||||||
return result1 && result2;
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calcOptimizedResult() {
|
public void calcOptimizedResult() {
|
||||||
double a = treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1) + (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1)) / Math.pow(treeDegreeW - 1, 2);
|
double a = 0;
|
||||||
double b = rootCountR * totalCountW;
|
if (treeHeightW > 1) {
|
||||||
double c = (totalCountR - rootCountR) * totalCountW;
|
if (treeDegreeW > 1) {
|
||||||
|
a = (treeHeightW - 1) *
|
||||||
double A = Math.sqrt(a * (treeHeightW - 1));
|
(treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1)
|
||||||
double B = Math.sqrt(b);
|
+ (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1)) / (treeDegreeW - 1) / (treeDegreeW - 1))
|
||||||
double C = Math.sqrt(c * (treeHeightR - 1));
|
* rootCountW;
|
||||||
wDelay = (long) (maxDelay * (A / (A + B + C)));
|
} else {
|
||||||
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
|
// treeDegreeW = 1
|
||||||
rDelay = (long) (maxDelay * (C / (A + B + C)));
|
a = (treeHeightW - 1) * (treeHeightW - 1) * treeHeightW / 2;
|
||||||
|
|
||||||
|
|
||||||
frequencySyncW = (treeHeightW - 1) / wDelay;
|
|
||||||
frequencySyncR = (treeHeightR - 1) / rDelay;
|
|
||||||
frequencySyncWR = 1.0 / w2rDelay;
|
|
||||||
|
|
||||||
totalData = (long) (maxDelay * dataSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
String[] nodeIds = new String[1500];
|
|
||||||
int[] writers = new int[1000];
|
|
||||||
int[] readers = new int[1000];
|
|
||||||
long maxDelay = 60;
|
|
||||||
int bandwidthUpload = 10 * 1024 * 1024;
|
|
||||||
int bandwidthDownload = 10 * 1024 * 1024;
|
|
||||||
int datasize = 10 * 1024;
|
|
||||||
|
|
||||||
PlanningWith1Expansivity planning = new PlanningWith1Expansivity(nodeIds, writers, readers, maxDelay, bandwidthDownload, bandwidthUpload, datasize);
|
|
||||||
|
|
||||||
long minTotalData = Long.MAX_VALUE;
|
|
||||||
String result = "";
|
|
||||||
for (int rootCountW = 1; rootCountW <= writers.length; ++rootCountW) {
|
|
||||||
for (int treeDegreeW = 2; treeDegreeW <= writers.length / rootCountW - 1; ++treeDegreeW) {
|
|
||||||
planning.adjustWriterTree(rootCountW, treeDegreeW);
|
|
||||||
for (int rootCountR = 1; rootCountR <= readers.length; ++rootCountR) {
|
|
||||||
for (int treeDegreeR = 2; treeDegreeR <= readers.length / rootCountR - 1; ++treeDegreeR) {
|
|
||||||
planning.adjustReaderTree(rootCountR, treeDegreeR);
|
|
||||||
planning.calcOptimizedResult();
|
|
||||||
if (!planning.readerTreeConstraint()) {
|
|
||||||
//System.out.println("reader");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!planning.writerTreeConstraint()) {
|
|
||||||
//System.out.println("writer");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!planning.writer2ReaderConstraint()) {
|
|
||||||
//System.out.println("writer2Reader");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (minTotalData > planning.totalData) {
|
|
||||||
minTotalData = planning.totalData;
|
|
||||||
result = planning.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
double b = rootCountR * totalCountW;
|
||||||
|
double c = (totalCountR - rootCountR) * (treeHeightR - 1) * totalCountW;
|
||||||
|
|
||||||
System.out.println(minTotalData);
|
double A = Math.sqrt(a);
|
||||||
System.out.println(result);
|
double B = Math.sqrt(b);
|
||||||
long end = System.currentTimeMillis();
|
double C = Math.sqrt(c);
|
||||||
System.out.println("took " + (end - start));
|
|
||||||
|
wDelay = (long) Math.ceil(maxDelay * (A / (A + B + C)));
|
||||||
|
w2rDelay = (long) Math.ceil(maxDelay * (B / (A + B + C)));
|
||||||
|
rDelay = (long) Math.ceil(maxDelay * (C / (A + B + C)));
|
||||||
|
|
||||||
|
|
||||||
|
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
|
||||||
|
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
|
||||||
|
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
|
||||||
|
|
||||||
|
totalData = (long) (dataSize
|
||||||
|
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package org.bdware.sc.crdt.planning;
|
package org.bdware.sc.crdt.planning;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PlanningWithkExpansivity extends SharableNetworkPlanning {
|
public class PlanningWithkExpansivity extends SharableNetworkPlanning {
|
||||||
private double k;
|
Map<Integer, Map<Integer, Double>> accumulationsCache;
|
||||||
|
private final double k;
|
||||||
|
private final double domainSize;
|
||||||
|
|
||||||
private double domainSize;
|
public PlanningWithkExpansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay,
|
||||||
|
int bandwidthDownload, int bandwidthUpload, int dataSize, double domainSize) {
|
||||||
public PlanningWithkExpansivity(String[] nodeIds, int[] writers, int[] readers, long maxDelay, int bandwidthDownload, int bandwidthUpload, int dataSize, double domainSize) {
|
|
||||||
this.nodeIds = nodeIds;
|
this.nodeIds = nodeIds;
|
||||||
this.writers = writers;
|
this.writers = writers;
|
||||||
this.readers = readers;
|
this.readers = readers;
|
||||||
@ -19,17 +23,25 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
|
|||||||
this.k = (domainSize - dataSize) / domainSize;
|
this.k = (domainSize - dataSize) / domainSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double kWithPow(double v) {
|
|
||||||
return Math.pow(k, (v - 1) / (treeDegreeW - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean writerTreeConstraint() {
|
public boolean writerTreeConstraint() {
|
||||||
double common = frequencySyncW * domainSize * (1 - kWithPow(Math.pow(treeDegreeW, treeHeightW - 2)));
|
if (frequencySyncW > 0) {
|
||||||
// 非叶子节点下载带宽
|
if (treeDegreeW > 1) {
|
||||||
boolean result1 = bandwidthDownload >= common * treeDegreeW;
|
double common = frequencySyncW * domainSize
|
||||||
// 非根节点上行带宽
|
* (1 - Math.pow(k, (Math.pow(treeDegreeW, treeHeightW - 1) - 1) / (treeDegreeW - 1)));
|
||||||
boolean result2 = bandwidthUpload >= common;
|
// 非叶子节点下载带宽
|
||||||
return result1 && result2;
|
boolean result1 = bandwidthDownload >= common * treeDegreeW;
|
||||||
|
// 非根节点上行带宽
|
||||||
|
boolean result2 = bandwidthUpload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
} else if (treeDegreeW == 1) {
|
||||||
|
double common = frequencySyncW * domainSize * (1 - Math.pow(k, treeHeightW - 1));
|
||||||
|
boolean result1 = bandwidthDownload >= common;
|
||||||
|
// 非根节点上行带宽
|
||||||
|
boolean result2 = bandwidthUpload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean writer2ReaderConstraint() {
|
public boolean writer2ReaderConstraint() {
|
||||||
@ -42,63 +54,68 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean readerTreeConstraint() {
|
public boolean readerTreeConstraint() {
|
||||||
double common = frequencySyncR * domainSize * (1 - Math.pow(k, totalCountW));
|
if (frequencySyncR > 0) {
|
||||||
// Reader非叶子节点上行带宽
|
double common = frequencySyncR * domainSize * (1 - Math.pow(k, totalCountW));
|
||||||
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
// Reader非叶子节点上行带宽
|
||||||
// Reader非根节点下载带宽
|
boolean result1 = bandwidthUpload >= common * treeDegreeR;
|
||||||
boolean result2 = bandwidthDownload >= common;
|
// Reader非根节点下载带宽
|
||||||
return result1 && result2;
|
boolean result2 = bandwidthDownload >= common;
|
||||||
|
return result1 && result2;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] accumulations = new double[1000];
|
double calcAccumulationWithK() {
|
||||||
|
if (accumulationsCache == null) {
|
||||||
double calcAccumulation(int H1) {
|
accumulationsCache = new HashMap<>();
|
||||||
if (accumulations[H1] > 0) {
|
}
|
||||||
return accumulations[H1];
|
int H1 = (int) treeHeightW;
|
||||||
|
int D1 = (int) treeDegreeW;
|
||||||
|
if (accumulationsCache.get(H1) != null && accumulationsCache.get(H1).get(D1) != null) {
|
||||||
|
return accumulationsCache.get(H1).get(D1);
|
||||||
}
|
}
|
||||||
double result = 0;
|
double result = 0;
|
||||||
for (int h = 1; h < H1; ++h) {
|
for (int h = 1; h < H1; ++h) {
|
||||||
result += (Math.pow(treeDegreeW, h) * (1 - kWithPow(Math.pow(treeDegreeW, H1 - h - 1))));
|
result +=
|
||||||
|
(Math.pow(D1, h) * (1 - Math.pow(k, (Math.pow(D1, H1 - h) - 1) / (D1 - 1))));
|
||||||
|
}
|
||||||
|
accumulationsCache.computeIfAbsent(H1, k -> new HashMap<>()).put(D1, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
double calcAccumulation() {
|
||||||
|
int H1 = (int) treeHeightW;
|
||||||
|
double result = 0;
|
||||||
|
for (int h = 1; h < H1; ++h) {
|
||||||
|
result += (1 - Math.pow(k, H1 - h));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calcOptimizedResult() {
|
public void calcOptimizedResult() {
|
||||||
double a = calcAccumulation((int) treeHeightW);
|
double a = 0;
|
||||||
|
if (treeDegreeW > 1) {
|
||||||
|
a = treeHeightW > 1 ? (treeHeightW - 1) * calcAccumulationWithK() * rootCountW : 0;
|
||||||
|
} else if (treeDegreeW == 1) {
|
||||||
|
a = treeHeightW > 1 ? (treeHeightW - 1) * calcAccumulation() * rootCountW : 0;
|
||||||
|
}
|
||||||
|
|
||||||
double b = rootCountR * rootCountW * (1 - Math.pow(k, treeNodeCountW));
|
double b = rootCountR * rootCountW * (1 - Math.pow(k, treeNodeCountW));
|
||||||
double c = (totalCountR - rootCountR) * (1 - Math.pow(k, totalCountW));
|
double c = treeHeightR > 1 ? (treeHeightR - 1) * (totalCountR - rootCountR) * (1 - Math.pow(k, totalCountW)) : 0;
|
||||||
|
|
||||||
double A = Math.sqrt(a * (treeHeightW - 1));
|
double A = Math.sqrt(a);
|
||||||
double B = Math.sqrt(b);
|
double B = Math.sqrt(b);
|
||||||
double C = Math.sqrt(c * (treeHeightR - 1));
|
double C = Math.sqrt(c);
|
||||||
wDelay = (long) (maxDelay * (A / (A + B + C)));
|
wDelay = (long) Math.ceil(maxDelay * (A / (A + B + C)));
|
||||||
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
|
w2rDelay = (long) Math.ceil(maxDelay * (B / (A + B + C)));
|
||||||
rDelay = (long) (maxDelay * (C / (A + B + C)));
|
rDelay = (long) Math.ceil(maxDelay * (C / (A + B + C)));
|
||||||
|
|
||||||
|
|
||||||
frequencySyncW = (treeHeightW - 1) / wDelay;
|
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
|
||||||
frequencySyncR = (treeHeightR - 1) / rDelay;
|
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
|
||||||
frequencySyncWR = 1.0 / w2rDelay;
|
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
|
||||||
|
|
||||||
totalData = (long) (maxDelay * domainSize * (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
totalData = (long) (domainSize
|
||||||
}
|
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
String[] nodeIds = new String[1500];
|
|
||||||
int[] writers = new int[1000];
|
|
||||||
int[] readers = new int[1000];
|
|
||||||
long maxDelay = 60;
|
|
||||||
int bandwidthUpload = 10 * 1024 * 1024;
|
|
||||||
int bandwidthDownload = 10 * 1024 * 1024;
|
|
||||||
int datasize = 10 * 1024;
|
|
||||||
double domainSize = 1000 * 1024;
|
|
||||||
|
|
||||||
PlanningWithkExpansivity planning = new PlanningWithkExpansivity(nodeIds, writers, readers, maxDelay, bandwidthDownload, bandwidthUpload, datasize, domainSize);
|
|
||||||
|
|
||||||
planning.adjustAndCalc();
|
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
System.out.println("took " + (end - start));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,47 +37,57 @@ public class SharableNetworkPlanning {
|
|||||||
|
|
||||||
protected long totalData;
|
protected long totalData;
|
||||||
|
|
||||||
|
protected static double logNM(double n, double m) {
|
||||||
|
return Math.log(m) / Math.log(n);
|
||||||
|
}
|
||||||
|
|
||||||
public void adjustWriterTree(int rootCountW, int treeDegreeW) {
|
public void adjustWriterTree(int rootCountW, int treeDegreeW) {
|
||||||
this.rootCountW = rootCountW;
|
this.rootCountW = rootCountW;
|
||||||
this.treeDegreeW = treeDegreeW;
|
this.treeDegreeW = treeDegreeW;
|
||||||
this.treeNodeCountW = Math.ceil(totalCountW / rootCountW);
|
this.treeNodeCountW = Math.ceil(totalCountW / rootCountW);
|
||||||
this.treeHeightW = Math.ceil(logNM(treeDegreeW, treeNodeCountW * (treeDegreeW - 1) + 1));
|
if (treeDegreeW > 1) {
|
||||||
|
this.treeHeightW = Math.ceil(logNM(treeDegreeW, treeNodeCountW * (treeDegreeW - 1) + 1));
|
||||||
|
} else {
|
||||||
|
this.treeHeightW = treeNodeCountW;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void adjustReaderTree(int rootCountR, int treeDegreeR) {
|
public void adjustReaderTree(int rootCountR, int treeDegreeR) {
|
||||||
this.rootCountR = rootCountR;
|
this.rootCountR = rootCountR;
|
||||||
this.treeDegreeR = treeDegreeR;
|
this.treeDegreeR = treeDegreeR;
|
||||||
this.treeNodeCountR = Math.ceil(totalCountR / rootCountR);
|
this.treeNodeCountR = Math.ceil(totalCountR / rootCountR);
|
||||||
this.treeHeightR = Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1));
|
if (treeDegreeR > 1) {
|
||||||
}
|
this.treeHeightR = Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1));
|
||||||
|
} else {
|
||||||
protected double logNM(double n, double m) {
|
this.treeHeightR = treeNodeCountR;
|
||||||
return Math.log(m) / Math.log(n);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void adjustAndCalc() {
|
protected void adjustAndCalc() {
|
||||||
long minTotalData = Long.MAX_VALUE;
|
long minTotalData = Long.MAX_VALUE;
|
||||||
String result = "";
|
String result = "";
|
||||||
for (int rootCountW = 1; rootCountW <= writers.length; ++rootCountW) {
|
for (int rootCountW = 1; rootCountW <= writers.length; ++rootCountW) {
|
||||||
for (int treeDegreeW = 2; treeDegreeW <= writers.length / rootCountW - 1; ++treeDegreeW) {
|
int nodeCountPerTree = (int) Math.ceil(writers.length * 1.0 / rootCountW);
|
||||||
|
for (int treeDegreeW = 1; treeDegreeW <= nodeCountPerTree; ++treeDegreeW) {
|
||||||
adjustWriterTree(rootCountW, treeDegreeW);
|
adjustWriterTree(rootCountW, treeDegreeW);
|
||||||
for (int rootCountR = 1; rootCountR <= readers.length; ++rootCountR) {
|
for (int rootCountR = 1; rootCountR <= readers.length; ++rootCountR) {
|
||||||
for (int treeDegreeR = 2; treeDegreeR <= readers.length / rootCountR - 1; ++treeDegreeR) {
|
int maxTreeDegreeR = (int) Math.ceil(readers.length * 1.0 / rootCountR);
|
||||||
|
for (int treeDegreeR = 1; treeDegreeR <= maxTreeDegreeR; ++treeDegreeR) {
|
||||||
adjustReaderTree(rootCountR, treeDegreeR);
|
adjustReaderTree(rootCountR, treeDegreeR);
|
||||||
calcOptimizedResult();
|
calcOptimizedResult();
|
||||||
if (!readerTreeConstraint()) {
|
if (!readerTreeConstraint()) {
|
||||||
//System.out.println("reader");
|
// System.out.println("reader");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!writerTreeConstraint()) {
|
if (!writerTreeConstraint()) {
|
||||||
//System.out.println("writer");
|
// System.out.println("writer");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!writer2ReaderConstraint()) {
|
if (!writer2ReaderConstraint()) {
|
||||||
//System.out.println("writer2Reader");
|
// System.out.println("writer2Reader");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (minTotalData > totalData) {
|
if (totalData > 0 && minTotalData > totalData) {
|
||||||
minTotalData = totalData;
|
minTotalData = totalData;
|
||||||
result = toString();
|
result = toString();
|
||||||
}
|
}
|
||||||
@ -120,13 +130,17 @@ public class SharableNetworkPlanning {
|
|||||||
readerOnlySet.add(i);
|
readerOnlySet.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int[] writerParents = allocateTreeNode(writerOnlySet, rwSet, (int) rootCountW, (int) treeDegreeW);
|
int[] writerParents = allocateTreeNode(writerOnlySet, rwSet, (int) rootCountW,
|
||||||
int[] readerParents = allocateTreeNode(readerOnlySet, rwSet, (int) rootCountR, (int) treeDegreeR);
|
(int) treeDegreeW, wDelay, (int) treeHeightW);
|
||||||
|
int[] readerParents = allocateTreeNode(readerOnlySet, rwSet, (int) rootCountR,
|
||||||
|
(int) treeDegreeR, rDelay, (int) treeHeightR);
|
||||||
System.out.println(readerParents);
|
System.out.println(readerParents);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] allocateTreeNode(Set<Integer> onlySet, Set<Integer> rwSet, int rootCount, int degree) {
|
private int[] allocateTreeNode(Set<Integer> onlySet, Set<Integer> rwSet, int rootCount,
|
||||||
|
int degree, long delay, int height) {
|
||||||
int[] result = new int[nodeIds.length];
|
int[] result = new int[nodeIds.length];
|
||||||
|
long[] writerInterval = new long[nodeIds.length];
|
||||||
Arrays.fill(result, -2);
|
Arrays.fill(result, -2);
|
||||||
|
|
||||||
Map<Integer, List<Integer>> children = new HashMap<>();
|
Map<Integer, List<Integer>> children = new HashMap<>();
|
||||||
@ -143,6 +157,7 @@ public class SharableNetworkPlanning {
|
|||||||
if (children.get(parentIdx).size() >= degree) {
|
if (children.get(parentIdx).size() >= degree) {
|
||||||
notFullNodesIdx.pop();
|
notFullNodesIdx.pop();
|
||||||
}
|
}
|
||||||
|
writerInterval[idx] = delay / (height - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,6 +174,7 @@ public class SharableNetworkPlanning {
|
|||||||
if (children.get(parentIdx).size() >= degree) {
|
if (children.get(parentIdx).size() >= degree) {
|
||||||
notFullNodesIdx.pop();
|
notFullNodesIdx.pop();
|
||||||
}
|
}
|
||||||
|
writerInterval[idx] = delay / (height - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,10 +188,10 @@ public class SharableNetworkPlanning {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder result = new StringBuilder();
|
String result = "[" + wDelay + "," + w2rDelay + "," + rDelay +
|
||||||
result.append("[").append(wDelay).append(",").append(w2rDelay).append(",").append(rDelay).append("]\n")
|
"]\n" + "writer tree: degree " + treeDegreeW +
|
||||||
.append("reader tree: degree ").append(treeDegreeR).append(", count ").append(rootCountR).append(",\n")
|
", count " + rootCountW + ",\n" + "reader tree: degree " + treeDegreeR + ", count " +
|
||||||
.append("writer tree: degree ").append(treeDegreeW).append(", count ").append(rootCountW);
|
rootCountR;
|
||||||
return result.toString();
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package org.bdware.sc.crdt.proxy;
|
|||||||
import org.bdware.crdt.counter.GCounter;
|
import org.bdware.crdt.counter.GCounter;
|
||||||
import org.bdware.sc.crdt.SharableVarState;
|
import org.bdware.sc.crdt.SharableVarState;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class GCounterProxy extends SharableVar<GCounter> {
|
public class GCounterProxy extends SharableVar<GCounter> {
|
||||||
|
|
||||||
public GCounterProxy(String varId, String cpId,
|
public GCounterProxy(String varId, String cpId,
|
||||||
@ -31,6 +33,13 @@ public class GCounterProxy extends SharableVar<GCounter> {
|
|||||||
return writerVar.read();
|
return writerVar.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Long> getM() {
|
||||||
|
if (readerVar != null) {
|
||||||
|
return readerVar.getM();
|
||||||
|
}
|
||||||
|
return writerVar.getM();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GCounter createDeltaCrdt(String nodeId, String varId) {
|
protected GCounter createDeltaCrdt(String nodeId, String varId) {
|
||||||
return new GCounter(nodeId, varId);
|
return new GCounter(nodeId, varId);
|
||||||
|
Loading…
Reference in New Issue
Block a user