Skip to content

Commit

Permalink
[Tutorial] Update hints for PEx
Browse files Browse the repository at this point in the history
[PEx] minor change
  • Loading branch information
aman-goel committed Sep 9, 2024
1 parent 199ffec commit 5c8abf0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public TooManyChoicesException(String loc, int numChoices) {
*/
public TooManyChoicesException(String loc, int numChoices, int numCalls) {
super(String.format("""
%s: too many choices generated from this location - total %d choices after %d choose calls.
Reduce the total number of choices generated here to at most %d, by reducing the number times this choose statement is called.
For example, limit the number of transactions/requests etc.""",
%s: too many choices generated from this statement - total %d choices after %d choose calls.
Reduce the total number of choices generated here to at most %d, by reducing the number of times this choose statement is called.""",
loc, numChoices, numCalls, PExGlobal.getConfig().getMaxChoicesPerStmtPerSchedule()));
}
}
9 changes: 6 additions & 3 deletions Tutorial/1_ClientServer/PSrc/Client.p
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ machine Client
print format ("Withdrawal with rId = {0} failed, account balance = {1}", resp.rId, resp.balance);
}

if (currentBalance > 10)
/* Hint 3: Reduce the number of times WithdrawAmount() is called by changing the above line to the following:
if (currentBalance > 10 && nextReqId < (accountId*100 + 5))
*/
{
print format ("Still have account balance = {0}, lets try and withdraw more", currentBalance);
goto WithdrawMoney;
Expand All @@ -81,9 +84,9 @@ machine Client
// function that returns a random integer between (1 to current balance + 1)
fun WithdrawAmount() : int {
return choose(currentBalance) + 1;
/* Hint 2: Decrease the amount of data non-determinism by changing the above line to the following:
return ((choose(5) * currentBalance) / 4) + 1;
*/
/* Hint 2: Reduce the number of choices by changing the above line to the following:
return ((choose(5) * currentBalance) / 4) + 1;
*/
}

state NoMoneyToWithDraw {
Expand Down
6 changes: 3 additions & 3 deletions Tutorial/1_ClientServer/PTst/TestDriver.p
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ fun CreateRandomInitialAccounts(numAccounts: int) : map[int, int]
var bankBalance: map[int, int];
while(i < numAccounts) {
bankBalance[i] = choose(100) + 10; // min 10 in the account
/* Hint 1: Decrease the amount of data non-determinism by changing the above line to the following:
bankBalance[i] = choose(5) + 10; // min 10 in the account
*/
/* Hint 1: Reduce the number of choices by changing the above line to the following:
bankBalance[i] = choose(10) + 10; // min 10 in the account
*/
i = i + 1;
}
return bankBalance;
Expand Down
4 changes: 2 additions & 2 deletions Tutorial/2_TwoPhaseCommit/PForeign/PExForeignCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Random;

public class PExForeignCode {
/* Not recommended to use data non-determinism in PEx foreign code
/* Not allowed to use data non-determinism in PEx foreign code. So we cannot do the following:
public static PNamedTuple ChooseRandomTransaction(PInt uniqueId) {
Map<String, PValue<?>> values = new HashMap<>();
Random rand = new Random();
Expand All @@ -18,5 +18,5 @@ public static PNamedTuple ChooseRandomTransaction(PInt uniqueId) {
return new PNamedTuple(values);
}
*/
*/
}

0 comments on commit 5c8abf0

Please sign in to comment.