Skip to content

Commit

Permalink
Added ability to censor test output from ParseTest
Browse files Browse the repository at this point in the history
  • Loading branch information
richardclegg committed Jul 27, 2022
1 parent b751def commit b97a4c9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
9 changes: 8 additions & 1 deletion feta/actions/ParseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ParseTest extends SimpleAction {

boolean directed_;
ParseNet parser_;
public boolean censored_;

public ParseTest(boolean directed) {
stoppingConditions_= new ArrayList<StoppingCondition>();
Expand All @@ -29,6 +30,12 @@ public void parseActionOptions(JSONObject obj) {
if (start != null)
startTime_=start;

Boolean cens= (Boolean)obj.get("Censored");
if (cens != null) {
censored_= cens;
} else {
censored_= false;
}
Long interval = (Long) obj.get("Interval");
if (interval != null) {
if (interval >= 0) {
Expand All @@ -54,6 +61,6 @@ public void execute() {
parser_.parseNetwork(time_,time_+interval_);
time_+=interval_;
}
parser_.writeToFile(fileName_);
parser_.writeToFile(fileName_,censored_);
}
}
11 changes: 11 additions & 0 deletions feta/operations/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class Operation {
private long time_;
private int noChoices_=0;
private Random generator_;
private boolean censored_= false;

/** updates network with the new nodes and links that occur in this operation
alternative is for this to happen in the Network interface */
Expand Down Expand Up @@ -44,6 +45,16 @@ public void setTime(long time) {
public ArrayList<int[]> getNodeOrders() {
return nodeOrders_;
}

/** When output, details should be limited*/
public boolean isCensored(){
return censored_;
}

/** limit details output*/
public void censor() {
censored_= true;
}

/** Helper methods */

Expand Down
6 changes: 5 additions & 1 deletion feta/operations/Star.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ public String toString() {
System.out.println("leafNodeNames should not be null");
}
for (String leaf: leafNodeNames_) {
str.append(leaf).append(" ");
if (isCensored()) {
str.append("ANON ");
} else {
str.append(leaf).append(" ");
}
}
if (internal_){
str.append("INTERNAL");
Expand Down
4 changes: 3 additions & 1 deletion feta/parsenet/ParseNet.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public ArrayList<Link> getNextLinkSet(ArrayList<Link> links) {
return linkSet;
}

public void writeToFile(String fname) {
public void writeToFile(String fname, boolean censored) {
try {
FileWriter fw = new FileWriter(fname);
bw_ = new BufferedWriter(fw);
for (Operation op: operations_) {
if (censored)
op.censor();
bw_.write(op+"\n");
// Print for debugging: System.out.println(op);
}
Expand Down
2 changes: 1 addition & 1 deletion feta/parsenet/ParseNetDirected.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private ArrayList<Operation> parseTypedLinks(ArrayList <Link> links, Network net
//System.out.println("Intersect Processing events as links for this time "+links.get(0).time_);
for (Link l1: links) {
opsSoFar.add(processAsLink(l1,net));
System.out.println("Added op");
//System.out.println("Added op");
}
return opsSoFar;
}
Expand Down
1 change: 1 addition & 0 deletions test/TestParse.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"Action": {
"ParseTest": {
"Censored" : true,
"Start": 1,
"Interval":1,
"MaxNodes": 34401,
Expand Down

0 comments on commit b97a4c9

Please sign in to comment.