Skip to content

Commit

Permalink
fixed sourceType
Browse files Browse the repository at this point in the history
  • Loading branch information
TheColdIce committed Nov 6, 2023
1 parent 176e88c commit d297bb0
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
datasets
AMLsim/target/*
AMLsim/target*
2 changes: 1 addition & 1 deletion AMLsim/scripts/transaction_graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ def count__patterns(self, threshold=2):
argv = sys.argv

# debug:
PARAM_FILES = '50K_accts'
PARAM_FILES = '20K_accts'
argv.append(f'paramFiles/{PARAM_FILES}/conf.json')

argc = len(argv)
Expand Down
6 changes: 3 additions & 3 deletions AMLsim/src/main/java/amlsim/AMLSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ private void loadAlertMemberFile(String alertFile) throws IOException {
model.updateEndStep(endStep);

} else { // Create a new AML typology object
AMLTypology model = AMLTypology.createTypology(modelID, minAmount, maxAmount, startStep, endStep, scheduleID, this.normalTxInterval); // TODO: add sarTxInterval
alert = new Alert(alertID, model, sourceType, this); // TODO: implement same structure as normal where the model has access to the alert
AMLTypology model = AMLTypology.createTypology(modelID, minAmount, maxAmount, startStep, endStep, scheduleID, this.normalTxInterval, sourceType); // TODO: add sarTxInterval
alert = new Alert(alertID, model, this); // TODO: implement same structure as normal where the model has access to the alert
alerts.put(alertID, alert);
}
Account account = getAccountFromID(accountID);
Expand Down Expand Up @@ -611,7 +611,7 @@ public static void main(String[] args) {

// Loading configuration JSON file instead of parsing command line arguments
//String confFile = args[0];
String paramFiles = "50K_accts";
String paramFiles = "20K_accts";
String confFile = "paramFiles/" + paramFiles + "/conf.json"; // debug

try {
Expand Down
10 changes: 6 additions & 4 deletions AMLsim/src/main/java/amlsim/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ public void step(SimState state) {
AMLSim.handleIncome(currentStep, "TRANSFER", this.monthlyIncome, this, this.isSAR, (long) -1, (long) 11);
}
// Handle monthly outcome, if 26th to 28th of the month, pay monthly expense
if (currentStep % 28 == this.stepMonthlyOutcome) {
if (currentStep == this.stepMonthlyOutcome) {
AMLSim.handleOutcome(currentStep, "TRANSFER", this.monthlyOutcome, this, this.isSAR, (long) -1, (long) 11);
this.stepMonthlyOutcome = 28 + random.nextInt(3);
int currentMonth = (int) (currentStep / 28);
this.stepMonthlyOutcome = 28 * (currentMonth + 1) + random.nextInt(3);
}
// Handle income
if (this.random.nextDouble() < this.probIncome) {
Expand All @@ -293,9 +294,10 @@ public void step(SimState state) {
AMLSim.handleIncome(currentStep, "TRANSFER", this.monthlyIncomeSar, this, this.isSAR, (long) -1, (long) 11);
}
// Handle monthly outcome, if 26th to 28th of the month, pay monthly expense
if (currentStep % 28 == this.stepMonthlyOutcome) {
if (currentStep == this.stepMonthlyOutcome) {
AMLSim.handleOutcome(currentStep, "TRANSFER", this.monthlyOutcome, this, this.isSAR, (long) -1, (long) 11);
this.stepMonthlyOutcome = 28 + random.nextInt(3);
int currentMonth = (int) (currentStep / 28);
this.stepMonthlyOutcome = 28 * (currentMonth + 1) + random.nextInt(3);
}
// Handle income
if (this.random.nextDouble() < this.probIncomeSar) {
Expand Down
7 changes: 1 addition & 6 deletions AMLsim/src/main/java/amlsim/Alert.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ public class Alert {
private List<Account> members; // Accounts involved in this alert
private Account mainAccount; // Main account of this alert
private AMLTypology model; // Transaction model
private String sourceType; // Source type of this alert
private AMLSim amlsim; // AMLSim main object

Alert(long alertID, AMLTypology model, String sourceType, AMLSim sim){
Alert(long alertID, AMLTypology model, AMLSim sim){
this.alertID = alertID;
//this.scheduleID = scheduleID;
//this.interval = interval;
this.members = new ArrayList<>();
this.mainAccount = null;
this.model = model;
this.model.setAlert(this);
this.sourceType = sourceType;
this.amlsim = sim;
}

Expand Down Expand Up @@ -106,8 +104,5 @@ public boolean isSAR(){
return this.mainAccount != null && this.mainAccount.isSAR();
}

public String getSourceType(){
return this.sourceType;
}
}

66 changes: 32 additions & 34 deletions AMLsim/src/main/java/amlsim/model/aml/AMLTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public abstract class AMLTypology extends AbstractTransactionModel {
// amount
// amount

protected long stepReciveFunds;
protected String sourceType;

/**
* Create an AML typology object (alert transaction model)
*
Expand All @@ -55,37 +58,37 @@ public abstract class AMLTypology extends AbstractTransactionModel {
* @return AML typology model object
*/
public static AMLTypology createTypology(int modelID, double minAmount, double maxAmount,
int startStep, int endStep, int scheduleID, int interval) {
int startStep, int endStep, int scheduleID, int interval, String sourceType) {
AMLTypology model;
switch (modelID) {
case AML_FAN_OUT:
model = new FanOutTypology(minAmount, maxAmount, startStep, endStep);
model = new FanOutTypology(minAmount, maxAmount, startStep, endStep, sourceType);
break;
case AML_FAN_IN:
model = new FanInTypology(minAmount, maxAmount, startStep, endStep);
model = new FanInTypology(minAmount, maxAmount, startStep, endStep, sourceType);
break;
case CYCLE:
model = new CycleTypology(minAmount, maxAmount, startStep, endStep);
model = new CycleTypology(minAmount, maxAmount, startStep, endStep, sourceType);
break;
case BIPARTITE:
model = new BipartiteTypology(minAmount, maxAmount, startStep, endStep, scheduleID, interval);
model = new BipartiteTypology(minAmount, maxAmount, startStep, endStep, scheduleID, interval, sourceType);
break;
case STACK:
model = new StackTypology(minAmount, maxAmount, startStep, endStep, scheduleID, interval);
model = new StackTypology(minAmount, maxAmount, startStep, endStep, scheduleID, interval, sourceType);
break;
case RANDOM:
model = new RandomTypology(minAmount, maxAmount, startStep, endStep);
model = new RandomTypology(minAmount, maxAmount, startStep, endStep, sourceType);
break;
case SCATTER_GATHER:
model = new ScatterGatherTypology(minAmount, maxAmount, startStep, endStep);
model = new ScatterGatherTypology(minAmount, maxAmount, startStep, endStep, sourceType);
break;
case GATHER_SCATTER:
model = new GatherScatterTypology(minAmount, maxAmount, startStep, endStep);
model = new GatherScatterTypology(minAmount, maxAmount, startStep, endStep, sourceType);
break;
default:
throw new IllegalArgumentException("Unknown typology model ID: " + modelID);
}
model.setParameters(startStep, endStep);
model.setParameters(startStep, endStep); // TODO: remove?
return model;
}

Expand All @@ -94,8 +97,6 @@ public static AMLTypology createTypology(int modelID, double minAmount, double m
protected double maxAmount;
protected long startStep;
protected long endStep;
protected long stepReciveFunds;
protected String sourceType;

/**
* Set parameters (timestamps and amounts) of transactions
Expand All @@ -117,27 +118,6 @@ public static AMLTypology createTypology(int modelID, double minAmount, double m
*/
public void setAlert(Alert ag) {
this.alert = ag;
this.sourceType = "TRANSFER"; //this.alert.getSourceType(); TODO: fix this, getSourceType() rturns null
// Set step for reciving illicit funds
if (this.sourceType.equals("TRANSFER")) {
if (this.startStep < 25) {
this.startStep = this.startStep + 25;
this.endStep = this.endStep + 25;
}
long s = this.startStep % 28;
long d;
if (s < 25) {
d = s + 3;
} else {
d = s - 25;
}
this.stepReciveFunds = this.startStep - d;
} else {
this.stepReciveFunds = this.startStep - alert.getSimulator().random.nextLong(7);
if (this.stepReciveFunds < 0) {
this.stepReciveFunds = this.startStep - alert.getSimulator().random.nextLong(this.startStep);
}
}
}

/**
Expand Down Expand Up @@ -167,11 +147,29 @@ public int getStepRange() {
* @param endStep End simulation step of alert transactions (any transactions
* cannot be carried out after this step)
*/
public AMLTypology(double minAmount, double maxAmount, int startStep, int endStep) {
public AMLTypology(double minAmount, double maxAmount, int startStep, int endStep, String sourceType) {
this.minAmount = minAmount;
this.maxAmount = maxAmount;
this.startStep = startStep;
this.endStep = endStep;
this.sourceType = sourceType;
// Set step for reciving illicit funds
if (this.sourceType.equals("TRANSFER")) {
if (this.startStep < 25) { // TODO: change this when inital balance is set as a transaction on step 0, if ML pattern starts before step 25 we'll assume the funds are in the inital balance.
this.startStep = this.startStep + 25;
this.endStep = this.endStep + 25;
}
long s = this.startStep % 28;
long d;
if (s < 25) {
d = s + 3;
} else {
d = s - 25;
}
this.stepReciveFunds = this.startStep - d;
} else {
this.stepReciveFunds = this.startStep; // TODO: implement some randomization
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions AMLsim/src/main/java/amlsim/model/aml/BipartiteTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class BipartiteTypology extends AMLTypology {

private Random random = AMLSim.getRandom();

public BipartiteTypology(double minAmount, double maxAmount, int minStep, int maxStep, int scheduleID, int interval) {
super(minAmount, maxAmount, minStep, maxStep);
public BipartiteTypology(double minAmount, double maxAmount, int minStep, int maxStep, int scheduleID, int interval, String sourceType) {
super(minAmount, maxAmount, minStep, maxStep, sourceType);

this.startStep = minStep; //alert.getStartStep();
this.endStep = maxStep; //alert.getEndStep();
Expand Down
4 changes: 2 additions & 2 deletions AMLsim/src/main/java/amlsim/model/aml/CycleTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class CycleTypology extends AMLTypology {
private Random random = AMLSim.getRandom();


CycleTypology(double minAmount, double maxAmount, int startStep, int endStep) {
super(minAmount, maxAmount, startStep, endStep);
CycleTypology(double minAmount, double maxAmount, int startStep, int endStep, String sourceType) {
super(minAmount, maxAmount, startStep, endStep, sourceType);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions AMLsim/src/main/java/amlsim/model/aml/FanInTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class FanInTypology extends AMLTypology {

private Random random = AMLSim.getRandom();

FanInTypology(double minAmount, double maxAmount, int start, int end) {
super(minAmount, maxAmount, start, end);
FanInTypology(double minAmount, double maxAmount, int start, int end, String sourceType) {
super(minAmount, maxAmount, start, end, sourceType);
}

public void setParameters(int schedulingID) {
Expand Down
4 changes: 2 additions & 2 deletions AMLsim/src/main/java/amlsim/model/aml/FanOutTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class FanOutTypology extends AMLTypology {

private long[] steps;

FanOutTypology(double minAmount, double maxAmount, int minStep, int maxStep) {
super(minAmount, maxAmount, minStep, maxStep);
FanOutTypology(double minAmount, double maxAmount, int minStep, int maxStep, String sourceType) {
super(minAmount, maxAmount, minStep, maxStep, sourceType);
}

public int getNumTransactions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class GatherScatterTypology extends AMLTypology {
private double scatterAmount = 0.0; // Scatter transaction amount will be defined after gather transactions
private Random random = AMLSim.getRandom();

GatherScatterTypology(double minAmount, double maxAmount, int startStep, int endStep) {
super(minAmount, maxAmount, startStep, endStep);
GatherScatterTypology(double minAmount, double maxAmount, int startStep, int endStep, String sourceType) {
super(minAmount, maxAmount, startStep, endStep, sourceType);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions AMLsim/src/main/java/amlsim/model/aml/RandomTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void setParameters(int modelID) {
// return alert.getMembers().size();
// }

RandomTypology(double minAmount, double maxAmount, int minStep, int maxStep) {
super(minAmount, maxAmount, minStep, maxStep);
RandomTypology(double minAmount, double maxAmount, int minStep, int maxStep, String sourceType) {
super(minAmount, maxAmount, minStep, maxStep, sourceType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class ScatterGatherTypology extends AMLTypology {
private double gatherAmount;
private Random random = AMLSim.getRandom();

ScatterGatherTypology(double minAmount, double maxAmount, int startStep, int endStep) {
super(minAmount, maxAmount, startStep, endStep);
ScatterGatherTypology(double minAmount, double maxAmount, int startStep, int endStep, String sourceType) {
super(minAmount, maxAmount, startStep, endStep, sourceType);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions AMLsim/src/main/java/amlsim/model/aml/StackTypology.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class StackTypology extends AMLTypology {
// return orig_members * mid_members + mid_members + bene_members;
// }

StackTypology(double minAmount, double maxAmount, int minStep, int maxStep, int scheduleID, int interval) {
super(minAmount, maxAmount, minStep, maxStep);
StackTypology(double minAmount, double maxAmount, int minStep, int maxStep, int scheduleID, int interval, String sourceType) {
super(minAmount, maxAmount, minStep, maxStep, sourceType);

this.startStep = minStep; //alert.getStartStep();
this.endStep = maxStep; //alert.getEndStep();
Expand Down
Binary file modified AMLsim/target/amlsim-1.0.0.jar
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/BipartiteTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/CycleTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/FanInTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/FanOutTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/GatherScatterTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/RandomTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/ScatterGatherTypology.class
Binary file not shown.
Binary file modified AMLsim/target/classes/amlsim/model/aml/StackTypology.class
Binary file not shown.
2 changes: 1 addition & 1 deletion AMLsim/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven
#Mon Nov 06 09:15:33 UTC 2023
#Mon Nov 06 09:18:46 UTC 2023
groupId=amlsim
artifactId=amlsim
version=1.0.0

0 comments on commit d297bb0

Please sign in to comment.