Skip to content

Commit

Permalink
Modify AppViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
TGNThump committed May 2, 2018
1 parent 541cb50 commit cef5464
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 118 deletions.
10 changes: 4 additions & 6 deletions GroupProjectRASQL/Heuristics/Heuristic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public abstract class Heuristic
protected Node root;
protected Node next;
protected bool isStarted = false;
protected bool isComplete { get { return isStarted && remainingNodes.Count == 0; } }
public bool isComplete { get { return isStarted && remainingNodes.Count == 0; } }
public bool isEnabled { get; set; } = true;
public String name { get; private set; }
public String description { get; private set; }

protected Queue<Node> remainingNodes = new Queue<Node>();

Expand Down Expand Up @@ -56,10 +59,5 @@ public void Reset()
// Abstract method run for each Node in the tree.
// returns true if it did anything.
abstract public bool Run(Node node);

public bool IsComplete()
{
return isComplete;
}
}
}
196 changes: 84 additions & 112 deletions GroupProjectRASQL/ViewModel/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,17 @@ public class ApplicationViewModel : Reactive
Parser.Parser sqlParser = new Parser.Parser("sql");
Parser.Parser raParser = new Parser.Parser("ra");

public Heuristic0 Heuristic0 { get; private set; }
public Heuristic1 Heuristic1 { get; private set; }
public Heuristic2 Heuristic2 { get; private set; }
public Heuristic3 Heuristic3 { get; private set; }
public Heuristic4 Heuristic4 { get; private set; }
public Heuristic5 Heuristic5 { get; private set; }

public Heuristic CurrentHeuristic { get {
if (Heuristic1 == null) return null;
if (!Heuristic1.IsComplete()) return Heuristic1;
if (!Heuristic2.IsComplete()) return Heuristic2;
if (!Heuristic3.IsComplete()) return Heuristic3;
if (!Heuristic4.IsComplete()) return Heuristic4;
return Heuristic5;
public List<Heuristic> Heurisitcs { get; private set; } = new List<Heuristic>();

public Heuristic CurrentHeuristic
{
get
{
foreach (Heuristic heuristic in Heurisitcs)
{
; if (heuristic.isEnabled && !heuristic.isComplete) return heuristic;
}
return null;
}
}

Expand All @@ -68,20 +65,32 @@ public Heuristic CurrentHeuristic { get {
public string Input_Type { get; set; } = "sql";

private string input_sql;
public string Input_SQL { get {
return input_sql;
} set {
this.Input_Valid_SQL = true;
this.input_sql = value;
}}
public string Input_SQL
{
get
{
return input_sql;
}
set
{
this.Input_Valid_SQL = true;
this.input_sql = value;
}
}

private string input_ra;
public string Input_RA { get {
return input_ra;
} set {
this.Input_Valid_RA = true;
this.input_ra = value;
} }
public string Input_RA
{
get
{
return input_ra;
}
set
{
this.Input_Valid_RA = true;
this.input_ra = value;
}
}

public string Output { get; private set; } = "";
public string Error { get; set; } = "";
Expand All @@ -91,6 +100,7 @@ public string Input_RA { get {
public ISimpleCommand ParseRA { get; private set; }
public ISimpleCommand Step { get; private set; }
public ISimpleCommand Complete { get; private set; }
public ISimpleCommand Auto { get; private set; }
public ISimpleCommand Reset { get; private set; }

private TreeNode<Operation> ops;
Expand All @@ -112,9 +122,9 @@ public ApplicationViewModel()
if (sql == "") { Input_Valid_SQL = false; return; }
List<State>[] stateSets = sqlParser.Parse(sql);
if (!sqlParser.IsValid(stateSets)) { Input_Valid_SQL = false; return; }
stateSets = sqlParser.FilterAndReverse(stateSets);
TreeNode<String> tree = sqlParser.parse_tree(sql, stateSets);
Expand Down Expand Up @@ -162,18 +172,13 @@ public ApplicationViewModel()
this.ops = RAToOps.Translate(tree, Relations.ToDictionary(relation => relation.name));
ops = new TreeNode<Operation>(new Query()) { ops };
Heuristic0 = new Heuristic0(ops);
Heuristic1 = new Heuristic1(ops);
Heuristic2 = new Heuristic2(ops);
Heuristic3 = new Heuristic3(ops);
Heuristic4 = new Heuristic4(ops);
Heuristic5 = new Heuristic5(ops);
Heuristic0.Complete();
new Heuristic0(ops).Complete();
this.Output = "<div class='card'><div class='card-body'>";
this.Output += ops.TreeToDebugString();
this.Output += "</div></div>";
Heurisitcs.Add(new Heuristic1(ops));
Heurisitcs.Add(new Heuristic2(ops));
Heurisitcs.Add(new Heuristic3(ops));
Heurisitcs.Add(new Heuristic4(ops));
Heurisitcs.Add(new Heuristic5(ops));
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
this.CurrentView = "output";
Expand All @@ -187,99 +192,66 @@ public ApplicationViewModel()
}
});

Step = new RelaySimpleCommand(() =>
Step = new RelaySimpleCommand(() =>
{
if (!Heuristic1.IsComplete())
{
Heuristic1.Step();
Output += "<div class='card'><div class='card-header'>Heuristic 1</div><div class='card-body'>";
}
else if (!Heuristic2.IsComplete())
{
Heuristic2.Step();
Output += "<div class='card'><div class='card-header'>Heuristic 2</div><div class='card-body'>";
}
else if (!Heuristic3.IsComplete())
{
Heuristic3.Step();
Output += "<div class='card'><div class='card-header'>Heuristic 3</div><div class='card-body'>";
}
else if (!Heuristic4.IsComplete())
try
{
Heuristic4.Step();
Output += "<div class='card'><div class='card-header'>Heuristic 4</div><div class='card-body'>";
if (CurrentHeuristic != null) CurrentHeuristic.Step();
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
}
else if (!Heuristic5.IsComplete())
catch (Exception e)
{
Heuristic5.Step();
Output += "<div class='card'><div class='card-header'>Heuristic 5</div><div class='card-body'>";
Console.WriteLine(e.ToString());
Error = e.Message.Replace(Environment.NewLine, "<br/>");
return;
}
else return;
Output += ops.TreeToDebugString();
Output += "</div></div>";
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
});

Complete = new RelaySimpleCommand(() =>
{
if (!Heuristic1.IsComplete())
{
Heuristic1.Complete();
Output += "<div class='card'><div class='card-header'>Heuristic 1</div><div class='card-body'>";
}
else if (!Heuristic2.IsComplete())
{
Heuristic2.Complete();
Output += "<div class='card'><div class='card-header'>Heuristic 2</div><div class='card-body'>";
}
else if (!Heuristic3.IsComplete())
{
Heuristic3.Complete();
Output += "<div class='card'><div class='card-header'>Heuristic 3</div><div class='card-body'>";
}
else if (!Heuristic4.IsComplete())
try
{
Heuristic4.Complete();
Output += "<div class='card'><div class='card-header'>Heuristic 4</div><div class='card-body'>";
if (CurrentHeuristic != null) CurrentHeuristic.Complete();
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
}
else if (!Heuristic5.IsComplete())
catch (Exception e)
{
Heuristic5.Complete();
Output += "<div class='card'><div class='card-header'>Heuristic 5</div><div class='card-body'>";
Console.WriteLine(e.ToString());
Error = e.Message.Replace(Environment.NewLine, "<br/>");
return;
}
else return;
Output += ops.TreeToDebugString();
Output += "</div></div>";
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
});

Reset = new RelaySimpleCommand(()=> {
List<State>[] stateSets = raParser.Parse(RA);
stateSets = raParser.FilterAndReverse(stateSets);
TreeNode<String> tree = raParser.parse_tree(RA, stateSets);
Squish(tree);
Reset = new RelaySimpleCommand(() =>
{
try
{
List<State>[] stateSets = raParser.Parse(RA);
stateSets = raParser.FilterAndReverse(stateSets);
TreeNode<String> tree = raParser.parse_tree(RA, stateSets);
this.ops = RAToOps.Translate(tree, Relations.ToDictionary(relation => relation.name));
ops = new TreeNode<Operation>(new Query()) { ops };
Squish(tree);
Heuristic0 = new Heuristic0(ops);
Heuristic1 = new Heuristic1(ops);
Heuristic2 = new Heuristic2(ops);
Heuristic3 = new Heuristic3(ops);
Heuristic4 = new Heuristic4(ops);
Heuristic5 = new Heuristic5(ops);
this.ops = RAToOps.Translate(tree, Relations.ToDictionary(relation => relation.name));
ops = new TreeNode<Operation>(new Query()) { ops };
Heuristic0.Complete();
new Heuristic0(ops).Complete();
this.Output = "<div class='card'><div class='card-body'>";
this.Output += ops.TreeToDebugString();
this.Output += "</div></div>";
Heurisitcs.Add(new Heuristic1(ops));
Heurisitcs.Add(new Heuristic2(ops));
Heurisitcs.Add(new Heuristic3(ops));
Heurisitcs.Add(new Heuristic4(ops));
Heurisitcs.Add(new Heuristic5(ops));
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
return;
this.OpsJSON = ops.Child().ToJSON().Replace("\"", "&quot;").Replace("'", "\"");
return;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Error = e.Message.Replace(Environment.NewLine, "<br/>");
return;
}
});
}

Expand Down

0 comments on commit cef5464

Please sign in to comment.