package paysim; import java.util.ArrayList; import sim.engine.SimState; import sim.engine.Steppable; public class ClientBeta extends SuperClient implements Steppable{ private String name = ""; private boolean willRepeat = false; boolean failed = false; private double[] probabilityArr; private ArrayList probList; private ArrayList stepsToRepeat = new ArrayList(); private long nrOfStepsToRepeat = 0; private ArrayList paramFile = new ArrayList(); String currType = ""; private CurrentStepHandler stepHandler = null; private double x; private double y; public double getDiff(ClientBeta c){ double xFactor = c.getX() - this.x; xFactor = xFactor * xFactor; double yFactor = c.getY() - this.y; yFactor = yFactor * yFactor; double result = xFactor + yFactor; result = Math.sqrt(result); return result; } public void move(PaySim paysim){ int randNrX = 0; int randNrY = 0; do { randNrX = paysim.random.nextInt()%5; } while (randNrX == 0); do { randNrY = paysim.random.nextInt()%5; } while (randNrY == 0); System.out.println("RandedX:\t" + randNrX + "\tRandedY:\t" + randNrY + "\n"); this.x += randNrX; this.y += randNrY; if(this.x > 1000){ this.x = 1000; }else if(this.x < 0){ this.x = 0; } if(this.y > 1000){ this.y = 1000; }else if(this.y < 0){ this.y = 0; } System.out.println("X:\t" + this.x + "\tY:\t" + this.y + "\n"); } @Override public void step(SimState state) { //System.out.println(this.name + "\tBegun\n"); handleAction(state); //If the action is to be repeated, then make the repetitions if(this.cont != null){ handleRepetition(state); } //System.out.println(this.name + "\tFinished\n"); } public long getNrOfStepsToRepeat() { return nrOfStepsToRepeat; } public void setNrOfStepsToRepeat(long nrOfStepsToRepeat) { this.nrOfStepsToRepeat = nrOfStepsToRepeat; } public void handleAction(SimState state){ PaySim paysim = (PaySim)state; //Must stored in properties int action = 0; //Based on the calculated probablity, an action is chosen do{ action = this.chooseAction(paysim, this.probabilityArr); if(action == -1){ if(this.probabilityArr.length == 0){ return; } } }while(action == -1); switch (action) { // CASH_IN case 1: // Manager.cashInCounter++; // System.out.println("CashInCounter is:\t" + Manager.cashInCounter + "\n"); handleCashIn(paysim); break; // CASH_OUT case 2: handleCashOut(paysim); break; // DEBIT case 3: handleDebit(paysim); break; // DEPOSIT case 4: handleDeposit(paysim); break; // PAYMENT case 5: handlePayment(paysim); break; //TRANSFER case 6: handleTransfer(paysim); break; } } public void handleRepetition(SimState state){ PaySim paysim = (PaySim)state; //Based on the nr of times to repeat, make the repetition for(int i=0; i getProbList() { return probList; } public boolean isWillRepeat() { return willRepeat; } public ClientBeta getRandomClientBeta(double amount, PaySim paysim){ ClientBeta ClientBetaToTransfer = new ClientBeta(); int counter = 0; do{ ClientBetaToTransfer = paysim.getClientsBeta().get(paysim.random.nextInt(paysim.getClientsBeta().size())); counter ++; if(counter > 50000){ break; } }while(ClientBetaToTransfer.getBalance() < amount); return ClientBetaToTransfer; } public Merchant getRandomMerchant(PaySim paysim){ Merchant m = paysim.getMerchants().get(paysim.random.nextInt(paysim.getMerchants().size())); return m; } public void setWillRepeat(boolean willRepeat) { this.willRepeat = willRepeat; } public void setProbList(ArrayList probList) { this.probList = probList; } private double getAmount(ActionProbability prob, PaySim paysim){ double amount = 0; do{ amount = paysim.random.nextGaussian() * prob.getStd() + prob.getAverage(); }while(amount <= 0); return amount; } private double getAmountRepetition(String type, int day, int hour, PaySim paysim){ AggregateTransactionRecord transRecord = this.stepHandler.getRecord(type, day, hour); if(transRecord == null){ return -1; } double amount = 0; do{ amount = paysim.random.nextGaussian() * Double.parseDouble(transRecord.gettStd()) + Double.parseDouble(transRecord.gettAvg()); }while(amount <= 0); return amount; } public ArrayList getStepsToRepeat() { return stepsToRepeat; } public void setStepsToRepeat(ArrayList stepsToRepeat) { this.stepsToRepeat = stepsToRepeat; } private ActionProbability getProb(String probToGet, PaySim p){ for(ActionProbability temp: this.probList){ if(temp.getType().equals(probToGet)){ return temp; } } return null; } private void printActionProbability(){ System.out.println("Printing prob\n"); for(ActionProbability p: this.probList){ System.out.println(p.getType() + "\n" + p.getNrOfTransactions() + "\n"); } System.out.println("\n\n"); } public ArrayList getParamFile() { return paramFile; } public void setParamFile(ArrayList paramFile) { this.paramFile = paramFile; } public CurrentStepHandler getStepHandler() { return stepHandler; } public void setStepHandler(CurrentStepHandler stepHandler) { this.stepHandler = stepHandler; } public double getX() { return x; } public void setX(double x) { this.x = x; } public double getY() { return y; } public void setY(double y) { this.y = y; } }