/// <summary> /// Ends the .akk unit test text. /// </summary> public static void CloseUnitTest(Tvar val, string goal) { string result = Convert.ToString(val.Out); testStr += "- " + TestGoal(goal) + ".Out =?= "; bool noQuotes = Interview.IsNumber(Convert.ToString(val.Out)) || Convert.ToString(val.Out) == "True" || Convert.ToString(val.Out) == "False"; if (val.IsEternal && val.Out.GetType() == new DateTime().GetType()) { // Handle eternal (known) Tdates testStr += Convert.ToDateTime(val.Out).ToString("yyyy-MM-dd"); } else if (val.IsEternal && noQuotes) { // Omit quotation marks around result for eternal (and known) Tnums and Tbools testStr += result.ToLower(); } else { // Include quotation marks for eternal Tsets and Tstrs, and for time-varying Tvars testStr += "\"" + result + "\""; } }
//napiseme jednu spolecnou obsluznou metodu pro vytvareni vsech objektu //tj. pro kruh, obdelnik i ctverec - spolecna obsluha udalosti // sender je parametr metody - odkaz na objekt, ktery udalost aktivoval // e je parametr metody - detaily o dane udalosti private void btnUniverzalniTvar_Click(object sender, EventArgs e) { int x = Convert.ToInt32(tbX.Text); int y = Convert.ToInt32(tbY.Text); int sirka = Convert.ToInt32(tbSirka.Text); int vyska = Convert.ToInt32(tbVyska.Text); //Kruh k = new Kruh(sirka); //Kruh k = new Kruh(colorDialog1.Color, x, y, sirka); //programovani pro univerzalni Tvar Tvar tvar = null; if (sender is Button) { Button b = sender as Button; //pretypovani na Button if (b.Name == "btnKruh") { tvar = new Kruh(colorDialog1.Color, x, y, sirka); } if (b.Name == "btnObdelnik") { tvar = new Obdelnik(colorDialog1.Color, x, y, sirka, vyska); } if (b.Name == "btnCtverec") { tvar = new Ctverec(colorDialog1.Color, x, y, sirka); } } //lbSeznamTvaru.Items.Add(k); lbSeznamTvaru.Items.Add(tvar); panel1.Refresh(); }
/// <summary> /// Assert a fact to the FactBase. /// </summary> private static void CoreAssert(string rel, object e1, object e2, object e3, Tvar val) { // Don't assert a fact that's already been asserted if (!HasBeenAsserted(rel, e1, e2, e3)) { // Assert the fact Fact f = new Fact(rel, e1, e2, e3, val); FactBase.Add(f); // TODO: This breaks when the objects are not Things (hence the try-catch) try { // Add Things to the ThingBase AddThing((Thing)e1); AddThing((Thing)e2); AddThing((Thing)e3); // Look for additional inferences that can be drawn, based on assumptions. Assumptions.TriggerInferences(rel, (Thing)e1, (Thing)e2, (Thing)e3, val); } catch { } } }
/// <summary> /// Sets a Tvar fact that establishes a relation between legal entities. /// </summary> public Fact(string rel, object arg1, object arg2, object arg3, Tvar val) { Relationship = rel; Arg1 = arg1; Arg2 = arg2; Arg3 = arg3; v = val; }
private void AddTvar(Tvar tvar) { if (aktualni != null) { tvary.Add(aktualni); UpdateHistory(); } aktualni = tvar; aktualni.NecoSeZmenilo += () => { UpdateProperties(); }; label1.Text = tvar.GetType().Name; UpdateProperties(); }
private void lbSeznamTvaru_SelectedIndexChanged(object sender, EventArgs e) { int index = lbSeznamTvaru.SelectedIndex; try { this.aktivniTvar = lbSeznamTvaru.Items[index] as Tvar; } catch { } tbObvod.Text = ""; tbObsah.Text = ""; }
static void Main(string[] args) { //Tvar t1 = new Tvar(); //nelze Obdelnik o1 = new Obdelnik(); //napiste metodu zadej sirku pro o2: //soukroma staticka vraci int jmenuje se VstupZKlavesnice a ma parametr String //Console.Write("zadej sirku pro o2: "); //string sirkaStr = Console.ReadLine(); int sirka = Program.VstupZKlavesnice("zadej sirku pro o2: "); //Convert.ToInt32(sirkaStr); //Console.Write("zadej vysku pro o2: "); //string vyskaStr = Console.ReadLine(); //int vyska = Convert.ToInt32(vyskaStr); int vyska = Program.VstupZKlavesnice("zadej vysku pro o2: "); //Obdelnik o2 = new Obdelnik(7, 4); Obdelnik o2 = new Obdelnik(sirka, vyska); Kruh k1 = new Kruh(); Kruh k2 = new Kruh(50); Ctverec c1 = new Ctverec(); Ctverec c2 = new Ctverec(7); //spolecne zpracovani vsech objektu v poli tvaru Tvar[] poleTvaru = new Tvar[6]; //0..5 poleTvaru[0] = o1; poleTvaru[1] = o2; poleTvaru[2] = k1; poleTvaru[3] = k2; poleTvaru[4] = c1; poleTvaru[5] = c2; for (int i = 0; i < poleTvaru.Length; i++) { Console.WriteLine(poleTvaru[i].ToString()); poleTvaru[i].Nakreslit(); Console.WriteLine("obvod je " + poleTvaru[i].VypocitatObvod()); Console.WriteLine("obsah je " + poleTvaru[i].VypocitatObsah()); Console.WriteLine("-------------"); } }
private void UpdateHistory() { flowLayoutPanel2.Controls.Clear(); foreach (var tvar in tvary) { Button btn = new Button(); btn.Text = tvar.GetType().Name; btn.Tag = tvar; btn.Click += (sender, e) => { var t = (Tvar)(((Button)sender).Tag); aktualni = t; label1.Text = t.GetType().Name; UpdateProperties(); }; flowLayoutPanel2.Controls.Add(btn); } }
/// <summary> /// Displays the engine's results of the interview session. /// </summary> private static void DisplayResults(Facts.Fact goal) { Console.WriteLine("\n"); // Indent and format results string tline = "\t" + goal.ValueAsString().Replace("\n", "\n\t"); // For eternal values, only show value if (goal.Value().IsEternal) { tline = tline.Replace("DawnOfTime ", ""); } // Concatenate question and answer string result = "\t" + goal.QuestionText() + "\n\n" + tline + "\n"; // Add result to test case Tvar testResult = goal.GetFunction().Invoke(); AkkTest.CloseUnitTest(testResult, goal.Relationship); Console.WriteLine(result); }
public Fact(string rel, object arg1, object arg2, object arg3) { Relationship = rel; Arg1 = arg1; Arg2 = arg2; Arg3 = arg3; v = null; }
/// <summary> /// Takes an income packet and instantiates a Hammurabi session. /// </summary> public Packet Assess(Packet request) { // Start timer DateTime startTime = DateTime.Now; // Pre-evaluate each goal to enable look-ahead short circuiting. // See Hammurabi | Core | Engine.cs, line ~81, for an explanation. foreach (Factoid g in request.Goals) { Facts.Fact gb = new Facts.Fact(g.Relationship, g.Arg1, g.Arg2, g.Arg3); gb.Value(); } // Start a fresh session // Facts.Clear(); Facts.GetUnknowns = true; Facts.Unknowns.Clear(); bool allDone = true; request.PercentageComplete = 100; // Assert facts into a Hammurabi session foreach (Factoid f in request.AssertedFacts) { AssertFact(f); } // Iterate through each goal foreach (Factoid g in request.Goals) { Facts.Fact gb = new Facts.Fact(g.Relationship, g.Arg1, g.Arg2, g.Arg3); // Assign to a variable so it's only evaluated once Tvar gbVal = gb.Value(); // Convert Tvar to timeline object g.Timeline = TvarToTimeline(gbVal); // All goals resolved? if (!gbVal.HasBeenDetermined) { allDone = false; } } // Stop looking for unknown facts Facts.GetUnknowns = false; // Determine the next fact and the percent complete if (!allDone) { // Factoid neededFact = new Factoid("Tnum","USC.Tit26.Sec151.ThresholdAmount","Jim","",""); // Facts.Fact f = new Facts.Fact("USC.Tit26.Sec151.ThresholdAmount", null, null, null); // Factoid neededFact = new Factoid(f); Factoid neededFact = new Factoid(Facts.Unknowns[0]); request.NeededFacts = new List <Factoid>() { neededFact }; request.PercentageComplete = Interactive.Engine.ProgressPercentage(Facts.Count(), Facts.Unknowns.Count); } // Add elapsed time to response object request.ResponseTimeInMs = Convert.ToInt32((DateTime.Now - startTime).TotalMilliseconds); return(request); }
/// <summary> /// Scans the assumption table, looking for forward-chaining inferences. /// </summary> public static void TriggerInferences(string rel, Thing e1, Thing e2, Thing e3, Tvar val) { foreach (Pair p in Pairs) { // If A, then B if (p.LeftHandPoint.Relationship == rel) { // TODO: Currently only handles expressions that are eternally true if (Tvar.EqualTo(p.LeftHandPoint.Value, val)) { // For each rightPoint.Arg number, get the corresponding Thing Thing[] args = new Thing[3]{e1,e2,e3}; int a1 = p.RightHandPoint.Arg1 - 1; // -1 b/c array is base-zero int a2 = p.RightHandPoint.Arg2 - 1; int a3 = p.RightHandPoint.Arg3 - 1; Thing t1 = a1 >= 0 ? args[a1] : null; Thing t2 = a2 >= 0 ? args[a2] : null; Thing t3 = a3 >= 0 ? args[a3] : null; Facts.Assert(t1, p.RightHandPoint.Relationship, t2, t3, p.RightHandPoint.Value); } } // If -B, then -A else if (p.RightHandPoint.Relationship == rel) { // If right-hand expression is always false... if (Tvar.EqualTo(p.RightHandPoint.Value, val).IsFalse) { // If the left-hand side is a boolean (non-booleans can't be negated)... if (Tvar.EqualTo(p.LeftHandPoint.Value, new Tbool(true)) || Tvar.EqualTo(p.LeftHandPoint.Value, new Tbool(false))) { // For each leftPoint.Arg number, get the corresponding Thing int r1 = p.RightHandPoint.Arg1; int r2 = p.RightHandPoint.Arg2; int r3 = p.RightHandPoint.Arg3; // I hope no one sees how ugly this is Thing t1, t2, t3; if (r1 == 1) t1 = e1; else if (r2 == 1) t1 = e2; else t1 = e3; if (r1 == 2) t2 = e1; else if (r2 == 2) t2 = e2; else t2 = e3; if (r1 == 3) t3 = e1; else if (r2 == 3) t3 = e2; else t3 = e3; // Assert -A Tbool leftVal = (Tbool)p.LeftHandPoint.Value; Facts.Assert(t1, p.LeftHandPoint.Relationship, t2, t3, !leftVal); } } } } }
public Point(string rel, int arg1, int arg2, int arg3, Tvar val) { Relationship = rel; Arg1 = arg1; Arg2 = arg2; Arg3 = arg3; Value = val; }
/// <summary> /// Assert a temporal property of one legal entity /// </summary> public static void Assert(object e1, string rel, Tvar val) { CoreAssert(rel, e1, null, null, val); }
// TODO: Implement data validation of some sort (e.g. consistency checking) /// <summary> /// Assert a temporal relation between legal entities (3) /// </summary> public static void Assert(object e1, string rel, object e2, object e3, Tvar val) { CoreAssert(rel, e1, e2, e3, val); }