feat: fix planning bug

This commit is contained in:
Xuxin Wang 2023-07-16 17:49:41 +08:00
parent a794bd3af4
commit 2384f6cc59
6 changed files with 208 additions and 231 deletions

View File

@ -3,9 +3,9 @@ package org.bdware.sc.crdt.planning;
public class PlanningTest {
public static void main(String[] args) {
final int nodeIdsCount = 1800;
final int writerCount = 1000;
final int readerCount = 1000;
final int nodeIdsCount = 1000;
final int writerCount = 500;
final int readerCount = 500;
String[] nodeIds = new String[nodeIdsCount];
int[] writers = new int[writerCount];
int[] readers = new int[readerCount];
@ -18,15 +18,18 @@ public class PlanningTest {
readers[i - nodeIdsCount + readerCount] = i;
}
}
long maxDelay = 60;
int bandwidthUpload = 100 * 1024 * 1024;
int bandwidthDownload = 100 * 1024 * 1024;
int datasize = 10 * 1024;
long maxDelay = 300;
int bandwidthUpload = 30;
int bandwidthDownload = 30;
int datasize = 10;
double domainSize = 100 * datasize;
PlanningWith0Expansivity planning0 = new PlanningWith0Expansivity(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);
PlanningWith0Expansivity planning0 = new PlanningWith0Expansivity(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();
planning0.adjustAndCalc();

View File

@ -1,7 +1,8 @@
package org.bdware.sc.crdt.planning;
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.writers = writers;
this.readers = readers;
@ -14,12 +15,15 @@ public class PlanningWith0Expansivity extends SharableNetworkPlanning {
}
public boolean writerTreeConstraint() {
double common = frequencySyncW * dataSize;
// 非叶子节点下载带宽
boolean result1 = bandwidthDownload >= common * treeDegreeW;
// 非根节点上行带宽
boolean result2 = bandwidthUpload >= common;
return result1 && result2;
if (frequencySyncW > 0) {
double common = frequencySyncW * dataSize;
// 非叶子节点下载带宽
boolean result1 = bandwidthDownload >= common * treeDegreeW;
// 非根节点上行带宽
boolean result2 = bandwidthUpload >= common;
return result1 && result2;
}
return true;
}
public boolean writer2ReaderConstraint() {
@ -32,79 +36,35 @@ public class PlanningWith0Expansivity extends SharableNetworkPlanning {
}
public boolean readerTreeConstraint() {
double common = frequencySyncR * dataSize;
// Reader非叶子节点上行带宽
boolean result1 = bandwidthUpload >= common * rootCountR;
// Reader非根节点下载带宽
boolean result2 = bandwidthDownload >= common;
return result1 && result2;
if (frequencySyncR > 0) {
double common = frequencySyncR * dataSize;
// Reader非叶子节点上行带宽
boolean result1 = bandwidthUpload >= common * treeDegreeR;
// Reader非根节点下载带宽
boolean result2 = bandwidthDownload >= common;
return result1 && result2;
}
return true;
}
public void calcOptimizedResult() {
double a = totalCountW - rootCountW;
double a = (treeHeightW - 1) * (totalCountW - rootCountW);
double b = rootCountR * rootCountW;
double c = totalCountR - rootCountR;
double c = (treeHeightR - 1) * (totalCountR - rootCountR);
double A = Math.sqrt(a * (treeHeightW - 1));
double A = Math.sqrt(a);
double B = Math.sqrt(b);
double C = Math.sqrt(c * (treeHeightR - 1));
double C = Math.sqrt(c);
wDelay = (long) (maxDelay * (A / (A + B + C)));
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
rDelay = (long) (maxDelay * (C / (A + B + C)));
frequencySyncW = (treeHeightW - 1) / wDelay;
frequencySyncR = (treeHeightR - 1) / rDelay;
frequencySyncWR = 1.0 / w2rDelay;
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
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;
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));
totalData = (long) (dataSize
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
}
}

View File

@ -1,7 +1,8 @@
package org.bdware.sc.crdt.planning;
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.writers = writers;
this.readers = readers;
@ -14,12 +15,15 @@ public class PlanningWith1Expansivity extends SharableNetworkPlanning {
}
public boolean writerTreeConstraint() {
double common = frequencySyncW * (treeNodeCountW - 1) * dataSize;
// 非叶子节点下载带宽
boolean result1 = bandwidthDownload >= common;
// 非根节点上行带宽
boolean result2 = bandwidthUpload >= common / treeDegreeW;
return result1 && result2;
if (frequencySyncW > 0) {
double common = frequencySyncW * (treeNodeCountW - 1) * dataSize;
// 非叶子节点下载带宽
boolean result1 = bandwidthDownload >= common;
// 非根节点上行带宽
boolean result2 = bandwidthUpload >= common / treeDegreeW;
return result1 && result2;
}
return true;
}
public boolean writer2ReaderConstraint() {
@ -32,79 +36,47 @@ public class PlanningWith1Expansivity extends SharableNetworkPlanning {
}
public boolean readerTreeConstraint() {
double common = frequencySyncR * totalCountW * dataSize;
// Reader非叶子节点上行带宽
boolean result1 = bandwidthUpload >= common * treeDegreeR;
// Reader非根节点下载带宽
boolean result2 = bandwidthDownload >= common;
return result1 && result2;
if (frequencySyncR > 0) {
double common = frequencySyncR * totalCountW * dataSize;
// Reader非叶子节点上行带宽
boolean result1 = bandwidthUpload >= common * treeDegreeR;
// Reader非根节点下载带宽
boolean result2 = bandwidthDownload >= common;
return result1 && result2;
}
return true;
}
public void calcOptimizedResult() {
double a = treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1) + (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1)) / Math.pow(treeDegreeW - 1, 2);
double b = rootCountR * totalCountW;
double c = (totalCountR - rootCountR) * totalCountW;
double A = Math.sqrt(a * (treeHeightW - 1));
double B = Math.sqrt(b);
double C = Math.sqrt(c * (treeHeightR - 1));
wDelay = (long) (maxDelay * (A / (A + B + C)));
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
rDelay = (long) (maxDelay * (C / (A + B + C)));
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 a = 0;
if (treeHeightW > 1) {
if (treeDegreeW > 1) {
a = (treeHeightW - 1) *
(treeHeightW * Math.pow(treeDegreeW, treeHeightW) / (treeDegreeW - 1)
+ (treeDegreeW - Math.pow(treeDegreeW, treeHeightW + 1)) / (treeDegreeW - 1) / (treeDegreeW - 1))
* rootCountW;
} else {
// treeDegreeW = 1
a = (treeHeightW - 1) * (treeHeightW - 1) * treeHeightW / 2;
}
}
double b = rootCountR * totalCountW;
double c = (totalCountR - rootCountR) * (treeHeightR - 1) * totalCountW;
System.out.println(minTotalData);
System.out.println(result);
long end = System.currentTimeMillis();
System.out.println("took " + (end - start));
double A = Math.sqrt(a);
double B = Math.sqrt(b);
double C = Math.sqrt(c);
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));
}
}

View File

@ -1,11 +1,15 @@
package org.bdware.sc.crdt.planning;
import java.util.HashMap;
import java.util.Map;
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.writers = writers;
this.readers = readers;
@ -19,17 +23,25 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
this.k = (domainSize - dataSize) / domainSize;
}
private double kWithPow(double v) {
return Math.pow(k, (v - 1) / (treeDegreeW - 1));
}
public boolean writerTreeConstraint() {
double common = frequencySyncW * domainSize * (1 - kWithPow(Math.pow(treeDegreeW, treeHeightW - 2)));
// 非叶子节点下载带宽
boolean result1 = bandwidthDownload >= common * treeDegreeW;
// 非根节点上行带宽
boolean result2 = bandwidthUpload >= common;
return result1 && result2;
if (frequencySyncW > 0) {
if (treeDegreeW > 1) {
double common = frequencySyncW * domainSize
* (1 - Math.pow(k, (Math.pow(treeDegreeW, treeHeightW - 1) - 1) / (treeDegreeW - 1)));
// 非叶子节点下载带宽
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() {
@ -42,63 +54,68 @@ public class PlanningWithkExpansivity extends SharableNetworkPlanning {
}
public boolean readerTreeConstraint() {
double common = frequencySyncR * domainSize * (1 - Math.pow(k, totalCountW));
// Reader非叶子节点上行带宽
boolean result1 = bandwidthUpload >= common * treeDegreeR;
// Reader非根节点下载带宽
boolean result2 = bandwidthDownload >= common;
return result1 && result2;
if (frequencySyncR > 0) {
double common = frequencySyncR * domainSize * (1 - Math.pow(k, totalCountW));
// Reader非叶子节点上行带宽
boolean result1 = bandwidthUpload >= common * treeDegreeR;
// Reader非根节点下载带宽
boolean result2 = bandwidthDownload >= common;
return result1 && result2;
}
return true;
}
double[] accumulations = new double[1000];
double calcAccumulation(int H1) {
if (accumulations[H1] > 0) {
return accumulations[H1];
double calcAccumulationWithK() {
if (accumulationsCache == null) {
accumulationsCache = new HashMap<>();
}
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;
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;
}
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 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 C = Math.sqrt(c * (treeHeightR - 1));
wDelay = (long) (maxDelay * (A / (A + B + C)));
w2rDelay = (long) (maxDelay * (B / (A + B + C)));
rDelay = (long) (maxDelay * (C / (A + B + C)));
double C = Math.sqrt(c);
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 = (treeHeightW - 1) / wDelay;
frequencySyncR = (treeHeightR - 1) / rDelay;
frequencySyncWR = 1.0 / w2rDelay;
frequencySyncW = wDelay > 0 ? (treeHeightW - 1) / wDelay : 0;
frequencySyncR = rDelay > 0 ? (treeHeightR - 1) / rDelay : 0;
frequencySyncWR = w2rDelay > 0 ? (1.0 / w2rDelay) : 0;
totalData = (long) (maxDelay * 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));
totalData = (long) (domainSize
* (frequencySyncW * a + frequencySyncWR * b + frequencySyncR * c));
}
}

View File

@ -37,47 +37,57 @@ public class SharableNetworkPlanning {
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) {
this.rootCountW = rootCountW;
this.treeDegreeW = treeDegreeW;
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) {
this.rootCountR = rootCountR;
this.treeDegreeR = treeDegreeR;
this.treeNodeCountR = Math.ceil(totalCountR / rootCountR);
this.treeHeightR = Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1));
}
protected double logNM(double n, double m) {
return Math.log(m) / Math.log(n);
if (treeDegreeR > 1) {
this.treeHeightR = Math.ceil(logNM(treeDegreeR, treeNodeCountR * (treeDegreeR - 1) + 1));
} else {
this.treeHeightR = treeNodeCountR;
}
}
protected void adjustAndCalc() {
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) {
int nodeCountPerTree = (int) Math.ceil(writers.length * 1.0 / rootCountW);
for (int treeDegreeW = 1; treeDegreeW <= nodeCountPerTree; ++treeDegreeW) {
adjustWriterTree(rootCountW, treeDegreeW);
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);
calcOptimizedResult();
if (!readerTreeConstraint()) {
//System.out.println("reader");
// System.out.println("reader");
continue;
}
if (!writerTreeConstraint()) {
//System.out.println("writer");
// System.out.println("writer");
continue;
}
if (!writer2ReaderConstraint()) {
//System.out.println("writer2Reader");
// System.out.println("writer2Reader");
continue;
}
if (minTotalData > totalData) {
if (totalData > 0 && minTotalData > totalData) {
minTotalData = totalData;
result = toString();
}
@ -120,13 +130,17 @@ public class SharableNetworkPlanning {
readerOnlySet.add(i);
}
}
int[] writerParents = allocateTreeNode(writerOnlySet, rwSet, (int) rootCountW, (int) treeDegreeW);
int[] readerParents = allocateTreeNode(readerOnlySet, rwSet, (int) rootCountR, (int) treeDegreeR);
int[] writerParents = allocateTreeNode(writerOnlySet, rwSet, (int) rootCountW,
(int) treeDegreeW, wDelay, (int) treeHeightW);
int[] readerParents = allocateTreeNode(readerOnlySet, rwSet, (int) rootCountR,
(int) treeDegreeR, rDelay, (int) treeHeightR);
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];
long[] writerInterval = new long[nodeIds.length];
Arrays.fill(result, -2);
Map<Integer, List<Integer>> children = new HashMap<>();
@ -143,6 +157,7 @@ public class SharableNetworkPlanning {
if (children.get(parentIdx).size() >= degree) {
notFullNodesIdx.pop();
}
writerInterval[idx] = delay / (height - 1);
}
}
@ -159,6 +174,7 @@ public class SharableNetworkPlanning {
if (children.get(parentIdx).size() >= degree) {
notFullNodesIdx.pop();
}
writerInterval[idx] = delay / (height - 1);
}
}
@ -172,10 +188,10 @@ public class SharableNetworkPlanning {
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("[").append(wDelay).append(",").append(w2rDelay).append(",").append(rDelay).append("]\n")
.append("reader tree: degree ").append(treeDegreeR).append(", count ").append(rootCountR).append(",\n")
.append("writer tree: degree ").append(treeDegreeW).append(", count ").append(rootCountW);
return result.toString();
String result = "[" + wDelay + "," + w2rDelay + "," + rDelay +
"]\n" + "writer tree: degree " + treeDegreeW +
", count " + rootCountW + ",\n" + "reader tree: degree " + treeDegreeR + ", count " +
rootCountR;
return result;
}
}

View File

@ -3,6 +3,8 @@ package org.bdware.sc.crdt.proxy;
import org.bdware.crdt.counter.GCounter;
import org.bdware.sc.crdt.SharableVarState;
import java.util.Map;
public class GCounterProxy extends SharableVar<GCounter> {
public GCounterProxy(String varId, String cpId,
@ -31,6 +33,13 @@ public class GCounterProxy extends SharableVar<GCounter> {
return writerVar.read();
}
public Map<String, Long> getM() {
if (readerVar != null) {
return readerVar.getM();
}
return writerVar.getM();
}
@Override
protected GCounter createDeltaCrdt(String nodeId, String varId) {
return new GCounter(nodeId, varId);