Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
qishipengqsp committed Sep 17, 2024
1 parent b3eeec4 commit 63ebb2c
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TransferEvent implements Serializable {
private final RandomGeneratorFarm randomFarm;
private final DegreeDistribution multiplicityDist;
private final float skippedRatio = 0.5f;
private int maxSkippedCount = 10;

public TransferEvent() {
randomFarm = new RandomGeneratorFarm();
Expand Down Expand Up @@ -40,16 +41,38 @@ public List<Transfer> transfer(List<Account> accounts, int blockId) {
resetState(blockId);

List<Transfer> transfers = new LinkedList<>();
LinkedList<Integer> availableToAccountIds = getIndexList(accounts.size()); // available transferTo accountIds
LinkedList<Integer> availableToAccountIds = getIndexList(accounts.size());
maxSkippedCount = Math.min(maxSkippedCount, (int) (skippedRatio * accounts.size()));

for (int i = 0; i < accounts.size(); i++) {
Account from = accounts.get(i);
// for (int i = 0; i < accounts.size(); i++) {
// Account from = accounts.get(i);
// int skippedCount = 0;
// for (int j = i + 1; j < accounts.size(); j++) {
// // termination
// if (skippedCount >= maxSkippedCount || from.getAvailableOutDegree() == 0) {
// break;
// }
// Account to = accounts.get(j);
// if (j == i || cannotTransfer(from, to)) {
// skippedCount++;
// continue;
// }
// long numTransfers = Math.min(multiplicityDist.nextDegree(),
// Math.min(from.getAvailableOutDegree(), to.getAvailableInDegree()));
// for (int mindex = 0; mindex < numTransfers; mindex++) {
// transfers.add(Transfer.createTransfer(randomFarm, from, to, mindex));
// }
// }
//
// }
for (int fromIndex = 0; fromIndex < accounts.size(); fromIndex++) {
Account from = accounts.get(fromIndex);
while (from.getAvailableOutDegree() != 0) {
int skippedCount = 0;
for (int j = 0; j < availableToAccountIds.size(); j++) {
int toIndex = availableToAccountIds.get(j);
Account to = accounts.get(toIndex);
if (toIndex == i || cannotTransfer(from, to)) {
if (toIndex == fromIndex || cannotTransfer(from, to)) {
skippedCount++;
continue;
}
Expand All @@ -62,22 +85,20 @@ public List<Transfer> transfer(List<Account> accounts, int blockId) {
availableToAccountIds.remove(j);
j--;
}
// TODO:
if (from.getAvailableOutDegree() == 0) {
break;
}
}
// end loop if all accounts are skipped
if (skippedCount >= availableToAccountIds.size() * skippedRatio) {
System.out.println("[Transfer] All accounts skipped for " + from.getAccountId());
// if (skippedCount == availableToAccountIds.size()) {
if (skippedCount >= maxSkippedCount) {
// System.out.println("[Transfer] All accounts skipped for " + from.getAccountId());
break;
}
}
}
return transfers;
}

// Transfer to self is not allowed
private boolean cannotTransfer(Account from, Account to) {
return from.getDeletionDate() < to.getCreationDate() + DatagenParams.activityDelta
|| from.getCreationDate() + DatagenParams.activityDelta > to.getDeletionDate()
Expand Down

0 comments on commit 63ebb2c

Please sign in to comment.