Commit eeb0aa3c authored by Jonathan Shahen's avatar Jonathan Shahen

Confirmed that Mohawk Reductions work!

parent 2c47cfd6
......@@ -4,10 +4,13 @@ import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Logger;
import mohawk.global.FileExtensions;
import org.apache.commons.cli.Options;
public class ConverterCUI {
public static final Logger logger = Logger.getLogger("mohawk-converter");
public static FileExtensions fileExt = new FileExtensions();
public static void main(String[] args) {
ConverterInstance inst = new ConverterInstance();
......@@ -66,6 +69,13 @@ public class ConverterCUI {
+ OptionString.LOGLEVEL.c() + "debug !exit");
System.out.println(OptionString.TO_ALL.c() + OptionString.SPECFILE.c() + "data/regressiontests/positive4.spec "
+ OptionString.LOGLEVEL.c() + "debug !exit");
System.out.println(OptionString.TO_ALL.c()
+ OptionString.SPECFILE.c("data/Mohawk/positive/test01.mohawk.mohawk.T")
+ OptionString.LOGLEVEL.c("debug") + "!exit");
System.out.println("");
System.out.println(OptionString.TO_ALL.c() + OptionString.SPECFILE.c("data/Mohawk/positive/")
+ OptionString.LOGLEVEL.c("debug") + OptionString.BULK.c() + OptionString.SPECEXT.c(fileExt.Mohawk_T)
+ "!exit");
}
}
......@@ -33,7 +33,7 @@ import org.apache.commons.cli.Options;
import org.apache.commons.lang3.StringUtils;
public class ConverterInstance {
private static final String VERSION = "v0.0.2";
private static final String VERSION = "v1.0.2";
private static final String AUTHORS = "Jonathan Shahen <jmshahen@uwaterloo.ca>";
// Logger Fields
public static final Logger logger = Logger.getLogger("mohawk-converter");
......@@ -117,7 +117,7 @@ public class ConverterInstance {
if (cmd.hasOption(OptionString.TO_ASAPTIME_NSA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime NSA...");
logger.info("[CONVERTING] Converting to ASAPTime NSA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeNSA (" + i + ")");
ConvertToASAPTimeNSA toASAPTimeNSA = new ConvertToASAPTimeNSA();
......@@ -136,7 +136,7 @@ public class ConverterInstance {
if (cmd.hasOption(OptionString.TO_ASAPTIME_SA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime SA...");
logger.info("[CONVERTING] Converting to ASAPTime SA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeSA (" + i + ")");
ConvertToASAPTimeSA toASAPTimeSA = new ConvertToASAPTimeSA();
......@@ -154,7 +154,7 @@ public class ConverterInstance {
}
if (cmd.hasOption(OptionString.TO_TROLE.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to TRole...");
logger.info("[CONVERTING] Converting to TRole... " + specFile.getName());
/* Timing */timing.startTimer("convertToTRole (" + i + ")");
ConvertToTRole toTRole = new ConvertToTRole();
......@@ -172,7 +172,7 @@ public class ConverterInstance {
}
if (cmd.hasOption(OptionString.TO_TRULE.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to TRule...");
logger.info("[CONVERTING] Converting to TRule... " + specFile.getName());
/* Timing */timing.startTimer("convertToTRule (" + i + ")");
ConvertToTRule toTRule = new ConvertToTRule();
......@@ -190,7 +190,7 @@ public class ConverterInstance {
}
if (cmd.hasOption(OptionString.TO_MOHAWK.toString()) || cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Mohawk...");
logger.info("[CONVERTING] Converting to Mohawk... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawk (" + i + ")");
ConvertToMohawk toMohawk = new ConvertToMohawk();
......@@ -208,7 +208,7 @@ public class ConverterInstance {
}
if (cmd.hasOption(OptionString.TO_MOHAWK_T.toString())) {
logger.info("[CONVERTING] Converting to Mohawk-T...");
logger.info("[CONVERTING] Converting to Mohawk-T... " + specFile.getName());
/* Timing */timing.startTimer("convertToMohawkT (" + i + ")");
FileWriter fw = new FileWriter(specFile.getAbsolutePath() + "_2");
......@@ -230,7 +230,7 @@ public class ConverterInstance {
logger.severe(e.getMessage());
}
logger.info("Converter Instance done running");
logger.info("[EOF] Converter Instance done running");
return 0;
}
......
......@@ -26,4 +26,13 @@ public enum OptionString {
public String c() {
return "-" + _str + " ";
}
/**
* Returns the commandline equivalent with the hyphen and a space following: LOGLEVEL("debug") -> "-loglevel debug "
* @param param
* @return
*/
public String c(String param) {
return "-" + _str + " " + param + " ";
}
}
......@@ -160,7 +160,7 @@ public class ConvertToASAPTimeSA extends ConvertTo {
}
// Convert Preconditions to the Role Indexes
System.out.println("[toASAPTimeSA_Rules] Rule: " + rule);
//System.out.println("[toASAPTimeSA_Rules] Rule: " + rule);
for (Role r : rule._preconditions) {
precondition.add(roleHelper.indexOf(r));
}
......
......@@ -39,6 +39,10 @@ public class ConvertToMohawk extends ConvertTo {
Query workableQuery = new Query(m.query);
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules()); // (3)
// Convert Query to Reduced ASAPTime SA Query and add any extra rules as needed
Mohawk_Query query = toMohawk_Query(workableQuery, workableRules, roleHelper, timeIntervalHelper);
workableRules = roleHelper.alwaysOnRules(workableRules, workableQuery, timeIntervalHelper); // (4)
workableRules = roleHelper.removeUninvokablePrecondtions(workableRules, false); // (6)
workableRules = roleHelper.removePrecondtionsCanRevoke(workableRules, false); // (6)
......@@ -57,15 +61,14 @@ public class ConvertToMohawk extends ConvertTo {
}
}
// Convert Query to Reduced ASAPTime SA Query and add any extra rules as needed
Mohawk_Query query = toMohawk_Query(workableQuery, newCARules, roleHelper, timeIntervalHelper);
boolean queryFound = query.finalize(roleHelperTemporality);
assert (queryFound == true) : "The query could not find the Goal Role!";
// Stats and logging
numberOfRules = newCARules.size() + newCRRules.size();
String template = ConvertTo.readFile(this.getClass().getResource("mohawkTemplate.st"));
ST st = new ST(template);
st.add("roles", roleHelperTemporality._roles);
st.add("roles", roleHelperTemporality._roles.toArray(new Role[0]));
st.add("users", new String[] { "AdminUser", "User" });
st.add("specuser", "User");
st.add("specrole", query.specRole);
......@@ -96,7 +99,7 @@ public class ConvertToMohawk extends ConvertTo {
return convertedStr;
}
private Mohawk_Query toMohawk_Query(Query query, ArrayList<MohawkCA_Rule> newCARules, RoleHelper roleHelper,
private Mohawk_Query toMohawk_Query(Query query, ArrayList<Rule> newCARules, RoleHelper roleHelper,
TimeIntervalHelper timeIntervalHelper) {
// Checking Conditions
assert (query._roles.size() > 0) : "The query must have atleast one Goal Role";
......@@ -111,7 +114,7 @@ public class ConvertToMohawk extends ConvertTo {
newRule._roleSchedule = new ArrayList<TimeSlot>(Arrays.asList(query._timeslot));
newRule._role = newGoalRole;
newCARules.add(new MohawkCA_Rule(newRule));
newCARules.add(newRule);
return q;
}
......
<! Roles role0 role1 role2 role3; !>
Roles <roles:{r|r._name}; separator=" ">;
Roles <roles:{r|<r._name>}; separator=" "> <adminrole>;
<! Users user0 user1 user2 user3 user4; !>
Users <users; separator=" ">;
<! UA <user4,Admin>; !>
UA \<<adminuser>,<adminrole>\>;
UA \<<adminuser>,<adminrole>>;
<! CR <Admin,role0> <Admin,role2>; !>
CR <canrevoke:{cr|\<<adminrole>,<cr.role>\>}; separator=" ">;
CR <canrevoke:{cr|\<<adminrole>,<cr.role>>}; separator=" ">;
<! CA <role3,role2,role0> <role3,role2&role1,role0> <role3,role2&role0,role1> <role3,TRUE,role1> <role3,role0,role1>; !>
CA <canassign:{ca|\<<adminrole>,<if(ca.precondition)><ca.precondition; separator="&"><else>TRUE<endif>,<ca.role>\>}; separator=" ">;
CA <canassign:{ca|\<<adminrole>,<if(ca.precondition)><ca.precondition; separator="&"><else>TRUE<endif>,<ca.role>>}; separator=" ">;
<! ADMIN user4; !>
ADMIN <adminuser>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment