private void Home_FormClosing(object sender, FormClosingEventArgs e) { if (PlEngine.IsInitialized) { PlEngine.PlCleanup(); } }//////
/// <summary> /// Wygenerowanie pierwszego rozwiązania. /// </summary> private void start_button_Click(object sender, EventArgs e) { try { String sciezka = @"..\..\..\alloc.pl"; if (!File.Exists(sciezka)) { throw new FileNotFoundException("Brak pliku: " + sciezka); } String crew = prepareCrewPrologList(); String flightsReqs = prepareFlightsRequirements(); //DefaultData.prepareDefaultRequirements(); if (!PlEngine.IsInitialized) { String[] param = { "-f", sciezka }; PlEngine.Initialize(param); } prologParams = new PlTermV(3); prologQuery = new PlQuery("matchTeams", prologParams); prologParams[1] = new PlTerm(flightsReqs); prologParams[2] = new PlTerm(crew); generateResultAndShow(); } catch (Exception ex) { MessageBox.Show("Wyjatek:\n\n" + ex.Message); } }
private void formBD_FormClosing(object sender, FormClosingEventArgs e) { PlQuery q = new PlQuery("salva"); q.NextSolution(); PlEngine.PlCleanup(); }
public void t_callback_with_subQuery() { Delegate d = new DelegateParameter1(assert_fact); PlEngine.RegisterForeign(d); Assert.IsTrue(PlQuery.PlCall("assert( (test(Result) :- member(X,[1,2,3]), assert_fact(X), findall(E, fact(E), Result)) )")); int count = 1; var q = new PlQuery("test(L)"); foreach (PlTermV s in q.Solutions) { switch (count) { case 1: Assert.AreEqual("[1]", s[0].ToString()); break; case 2: Assert.AreEqual("[1,2]", s[0].ToString()); break; case 3: Assert.AreEqual("[1,2,3]", s[0].ToString()); break; } //Console.WriteLine(s[0].ToString()); count++; } }
public static void Ex3() { if (!PlEngine.IsInitialized) { String[] param = { "-q" }; // suppressing informational and banner messages PlEngine.Initialize(param); // Test 1 //PlQuery.PlCall("assert(father(martin, inka))"); //Console.WriteLine(PlQuery.PlCall("father(martin, inkal)")); Del myComp = DoStuff; PlEngine.RegisterForeign(null, "mmm", 5, myComp); Console.WriteLine(PlQuery.PlCall("mmm(3, 6, 9, X, Y)")); using (PlQuery q = new PlQuery("mmm(3, 6, 9, X, Y)")) { foreach (PlQueryVariables v in q.SolutionVariables) { Console.WriteLine(v["X"].ToString()); Console.WriteLine(v["Y"].ToString()); } } PlEngine.PlCleanup(); } }
private void Juego_Load(object sender, EventArgs e) { PlEngine.PlCleanup(); Environment.SetEnvironmentVariable("Path", @"C:\\Program Files (x86)\\swipl\\bin"); string[] p = { "-q", "-f", @"Prolog\\matriz.pl" }; PlEngine.Initialize(p); }
public static bool Start(string filePath) { if (PlEngine.IsInitialized) { return(true); } string currentSystemPath = Environment.GetEnvironmentVariable("Path"); Environment.SetEnvironmentVariable(@"SWI_HOME_DIR", @"swipl"); Environment.SetEnvironmentVariable(@"Path", currentSystemPath + @";swipl;swipl\bin"); string[] args = { "-q", "-f", filePath }; try { PlEngine.Initialize(args); } catch { return(false); } return(true); }
private void startGame() { if (!PlEngine.IsInitialized) { // Thread clean = new Thread(); //string filename = @"C:\Users\Mathieu\Documents\Visual Studio 2015\Projects\TarotAfricain\TarotAfricain\Prolog\prolog.pro"; string filename = "TarotAfrikMulti.pl"; string text = System.IO.File.ReadAllText(filename); string serialNames = SerializeList(names); string serialIsIa = SerializeList(isIa); String[] param = { "-q", "-f", filename }; string query = "playGame(" + serialNames + ", " + serialIsIa + ", " + nbCarte.ToString() + "), write('end')."; PlEngine.Initialize(param); Debug.WriteLine(PlEngine.IsInitialized); Debug.WriteLine(PlEngine.PlThreadSelf()); //Debug.WriteLine("Attachement : " + PlEngine.PlThreadAttachEngine()); PlEngine.SetStreamFunctionWrite(SbsSW.SwiPlCs.Streams.PlStreamType.Output, stdout); InitializeCallBack(); PlQuery.PlCall(query); Debug.WriteLine("end"); } }
private void button1_Click(object sender, EventArgs e) // cai dat nut start trong form { if (Checkload == false) { MessageBox.Show("Phai load file truoc", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string s = "C:/Users/Hasegawa/Documents/Visual Studio 2015/Projects/pplt/pplt/sourceimgandprologcode/" + tenfilepl; string query = "consult('" + s + "')"; string[] p = { "-q", "-f", query }; PlEngine.Initialize(p); PlQuery q = new PlQuery(query); Assert.IsTrue(q.NextSolution()); using (var a = new PlQuery(querytextbox)) { int i = 0; foreach (var sol in a.SolutionVariables) { if (i % 2 == 0) { resultquery.Add(sol["P"].ToString()); } i++; if (i > Max) { break; } } PlEngine.PlCleanup(); } textBox1.Text = "List Thu " + index + " la P= " + resultquery[index]; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (!System.IO.Directory.Exists("C:\\Program Files (x86)\\swipl\\") && !System.IO.Directory.Exists("C:\\Program Files\\swipl\\")) { MessageBox.Show("Prolog chưa được cài đăt hoặc vị trí sai, vui lòng cài đặt Prolog 6.6.5 vào vị trí mặc định trên ổ C và chọn lại đường dẫn đến thư mục swipl cài đặt Prolog, nếu không chương trình không thể chạy!"); FolderBrowserDialog path = new FolderBrowserDialog(); path.ShowDialog(); String FolderPath = path.SelectedPath; Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"" + FolderPath); } else if (System.IO.Directory.Exists("C:\\Program Files (x86)\\swipl\\")) { Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files (x86)\swipl"); } else if (System.IO.Directory.Exists("C:\\Program Files\\swipl\\")) { Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\swipl"); } if (!PlEngine.IsInitialized) { String[] empty_param = { "" }; PlEngine.Initialize(empty_param); Application.Run(new frm_Main()); PlEngine.PlCleanup(); } }
static private readonly String[] EmptyParam = { "-q" }; // suppressing informational and banner messages // static public String[] EmptyParam = { "-nosignals" }; // static public String[] EmptyParam = { "--quit"}; static private void InitializePlEngine() { if (!PlEngine.IsInitialized) { PlEngine.Initialize(EmptyParam); } }
static void Main(string[] args) { // ------------ // przyklad z instrukcji do wrappera SwiPlCs : //Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\swipl\bin"); if (PlEngine.IsInitialized) { return; } String[] param = { /*"-q"*/ }; // suppressing informational and banner messages PlEngine.Initialize(param); PlQuery.PlCall("assert(father(martin, inka))"); PlQuery.PlCall("assert(father(uwe, gloria))"); PlQuery.PlCall("assert(father(uwe, melanie))"); PlQuery.PlCall("assert(father(uwe, ayala))"); using (var q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)")) { foreach (var v in q.SolutionVariables) { Console.WriteLine(v["L"].ToString()); } Console.WriteLine("all child's from uwe:"); q.Variables["P"].Unify("uwe"); foreach (var v in q.SolutionVariables) { Console.WriteLine(v["C"].ToString()); } } PlEngine.PlCleanup(); Console.WriteLine("finshed!"); }
public static void RegisterPLCSForeigns() { CreatorThread = Thread.CurrentThread; RegisterMainThread(); ShortNameType = new Dictionary <string, Type>(); ShortNameType["string"] = typeof(String); ShortNameType["object"] = typeof(Object); ShortNameType["sbyte"] = typeof(sbyte); // libpl.PL_agc_hook(new AtomGCHook(Tracker_FreeAtom)); //ShortNameType = new PrologBackedDictionary<string, Type>(null, "shortTypeName"); //PlEngine.RegisterForeign(null, "cliFindClass", 2, new DelegateParameter2(PrologCli.cliFindClass), PlForeignSwitches.None); PlEngine.RegisterForeign(ExportModule, "cli_load_assembly", 1, new DelegateParameter1(PrologCLR.cliLoadAssembly), PlForeignSwitches.None); if (VerboseStartup) { ConsoleWriteLine("RegisterPLCSForeigns"); } InternMethod(null, "cwl", typeof(Console).GetMethod("WriteLine", ONE_STRING)); Type t = typeof(PrologCLR); InternMethod(ExportModule, "cli_load_assembly_methods", t.GetMethod("cliLoadAssemblyMethods")); InternMethod(t.GetMethod("cliAddAssemblySearchPath"), "cli_"); InternMethod(t.GetMethod("cliRemoveAssemblySearchPath"), "cli_"); AddForeignMethods(t, false, "cli_"); RegisterJPLForeigns(); if (VerboseStartup) { ConsoleWriteLine("done RegisterPLCSForeigns"); } }
private void FormNBA_FormClosing(object sender, FormClosingEventArgs e) { PlQuery zatvoriDatoteku = new PlQuery("zatvoriDatoteku"); zatvoriDatoteku.NextSolution(); PlEngine.PlCleanup(); }
public static void init() { SpaceForm.self.tbELRuleInput.Text = ""; SpaceForm.self.tbELOutput.Text = ""; SpaceForm.self.tbELDomainTheory.Text = ""; if (!PlEngine.IsInitialized) { try { PlEngine.Initialize(new string[] { "-q" }); } catch { //32 on 64 bit Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files (x86)\swipl"); try { PlEngine.Initialize(new string[] { "-q" }); } catch { //64/32 bit only Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\swipl"); PlEngine.Initialize(new string[] { "-q" }); } } PlQuery.PlCall("consult('" + (File.Exists("./source.pl") ? "./source.pl" : "../../source.pl") + "')"); } logApp("---Init---"); }
static void Main(string[] args) { //Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc"); // or boot64.prc if (!PlEngine.IsInitialized) { String[] param = { "-q" }; // suppressing informational and banner messages PlEngine.Initialize(param); PlQuery.PlCall("assert(father(martin, inka))"); PlQuery.PlCall("assert(father(uwe, gloria))"); PlQuery.PlCall("assert(father(uwe, melanie))"); PlQuery.PlCall("assert(father(uwe, ayala))"); using (var q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)")) { foreach (PlQueryVariables v in q.SolutionVariables) { Console.WriteLine(v["L"].ToString()); } Console.WriteLine("all children from uwe:"); q.Variables["P"].Unify("uwe"); foreach (PlQueryVariables v in q.SolutionVariables) { Console.WriteLine(v["C"].ToString()); } } PlEngine.PlCleanup(); Console.WriteLine("finshed!"); } }
public List <List <SWIPrologServiceLibrary.SolutionVariable> > GetSolutionVariables(string query) { PlEngine.PlThreadAttachEngine(); var outerList = new List <List <SolutionVariable> >(); using (PlQuery q = new PlQuery(query)) { foreach (PlQueryVariables plQueryVariable in q.SolutionVariables) { var innerList = new List <SolutionVariable>(); foreach (string variableName in q.VariableNames) { innerList.Add(new SolutionVariable() { Variable = variableName, Value = plQueryVariable[variableName].ToString() }); } outerList.Add(innerList); } } return(outerList); }
//Nuevas.. /// <summary> /// Abre la conexion con el archivo de pl. /// </summary> public void abrirConexionProlog() { //Lee las variables del entorno, donde se encuentra Ubicado prolog.exe. Environment.SetEnvironmentVariable("Path", @"C:\\Program Files (x86)\\swipl\\bin"); String[] param = { "-q", "-f", @"conexion.pl" }; //Busca el archivo de conocimiento, esta dentro de debug PlEngine.Initialize(param); //Inicializa el archivo de conocimiento. }
private void button2_Click(object sender, EventArgs e) { puntos[click] = 0; click--; if (click == 0) { btn_atras.Enabled = false; btn_siguiente.Enabled = true; btn_finalizar.Enabled = false; click = 0; puntos[click] = 0; } else if (click == 5) { btn_atras.Enabled = true; btn_siguiente.Enabled = false; btn_finalizar.Enabled = true; click = 5; } else { btn_atras.Enabled = true; btn_siguiente.Enabled = true; btn_finalizar.Enabled = false; } switch (click) { case 0: cargarPreguntas("sistemas"); break; case 1: cargarPreguntas("administracion"); break; case 2: cargarPreguntas("gastronomia"); break; case 3: cargarPreguntas("civil"); break; case 4: cargarPreguntas("medicina"); break; case 5: cargarPreguntas("arqueologia"); break; } PlEngine.PlCleanup(); }
public static void LoadNonDetExamples() { Fn015.Register(); const PlForeignSwitches Nondeterministic = PlForeignSwitches.Nondeterministic; PlEngine.RegisterForeign(null, "foo2", 2, new DelegateParameterBacktrack2(FooTwo), Nondeterministic); PlEngine.RegisterForeign(null, "foo3", 3, new DelegateParameterBacktrackVarArgs(FooThree), Nondeterministic | PlForeignSwitches.VarArgs); }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { if (PlEngine.IsInitialized) { PlEngine.PlCleanup(); } Application.Exit(); }
public static void InternMethod(string module, string pn, AnyMethod d) { if (!PlEngine.SaveRegisterForeign(module, pn.ToString(), -1, d)) { return; } InternMethod(module, pn, d.Method); }
//[TestMethod] public void StreamRead() { PlEngine.SetStreamReader(Sread); // NOTE: read/1 needs a dot ('.') at the end PlQuery.PlCall("assert( (test_read(A) :- read(A)) )"); PlTerm t = PlQuery.PlCallQuery("test_read(A)"); // Assert.AreEqual(ref_string_read, t.ToString() + "."); }
private void Form1_Load(object sender, EventArgs e) { panel1.BackColor = Color.FromArgb(125, Color.Black); Environment.SetEnvironmentVariable("Path", @"C:\\PROGRAM FILES (x86)\\swipl\bin"); string[] p = { "-q", "-f", @"componentes.pl" }; PlEngine.Initialize(p); cargarDatosCombobox(); }
private void Form1_Load(object sender, EventArgs e) { //Ruta de instalacion de prolog Environment.SetEnvironmentVariable("Path", @"C:\\Program Files (x86)\\swipl\bin"); //Cargar archivo prilig string[] p = { "-q", "-f", @"boxeador.pl" }; PlEngine.Initialize(p); }
public void Initialize(params string[] initParams) { if (PlEngine.IsInitialized) { return; } PlEngine.Initialize(initParams); }
public SWIPrologService2() { if (!PlEngine.IsInitialized) { String[] param = { "-q" }; // suppressing informational and banner messages PlEngine.Initialize(param); } }
public void Decide() { if (!PlEngine.IsInitialized) { string[] param = { "-q" }; PlEngine.Initialize(param); PlQuery.PlCall("consult('HutBuiAct')"); PlQuery.PlCall("assert(done(" + this.action + "))"); PlQuery.PlCall("assert(in(" + this.InnerPosition.X + "," + this.InnerPosition.Y + "))"); PlQuery.PlCall("assert(facing(" + this.a + "))"); PlQuery.PlCall("assert(timePassed(" + this.timePassed + "))"); PlQuery.PlCall("assert(leftmoves(" + this.leftmoves + "))"); Console.WriteLine("assert(done(" + this.action + "))"); Console.WriteLine("assert(in(" + this.InnerPosition.X + "," + this.InnerPosition.Y + "))"); Console.WriteLine("assert(facing(" + this.a + "))"); Console.WriteLine("assert(timePassed(" + this.timePassed + "))"); Console.WriteLine("assert(leftmoves(" + this.leftmoves + "))"); if (this.isDirty()) { PlQuery.PlCall("assert(dirty(" + this.InnerPosition.X + "," + this.InnerPosition.Y + "))"); Console.WriteLine("assert(dirty(" + this.InnerPosition.X + "," + this.InnerPosition.Y + "))"); } for (int i = 0; i < 4; i++) { string OsbtacleType = this.TypeOfObstacle(this.upFront()); if (OsbtacleType != null) { Point upfront = this.Outer2Inner(this.upFront()); Console.WriteLine("assert(obstacle(" + upfront.X + "," + upfront.Y + ",both))"); Console.WriteLine("assert(obstacle(" + upfront.X + "," + upfront.Y + "," + OsbtacleType + "))"); PlQuery.PlCall("assert(obstacle(" + upfront.X + "," + upfront.Y + ",both))"); PlQuery.PlCall("assert(obstacle(" + upfront.X + "," + upfront.Y + "," + OsbtacleType + "))"); } this.Turn90(); } foreach (Point w in this.weight.Keys) { if (double.IsPositiveInfinity(this.weight[w])) { PlQuery.PlCall("assert(wasweight(" + w.X + "," + w.Y + ",inf))"); Console.WriteLine("assert(wasweight(" + w.X + "," + w.Y + ",inf))"); } else { PlQuery.PlCall("assert(wasweight(" + w.X + "," + w.Y + "," + this.weight[w] + "))"); Console.WriteLine("assert(wasweight(" + w.X + "," + w.Y + "," + this.weight[w] + "))"); } } using (var q = new PlQuery("do(A)")) { PlQueryVariables v = q.SolutionVariables.ElementAt(0); this.action = v["A"].ToString(); Console.WriteLine("do(" + this.action + ")"); } PlEngine.PlCleanup(); } }
public void MT_3() { System.Diagnostics.Trace.WriteLine("MT3:" + System.Threading.Thread.CurrentThread.ManagedThreadId); PlEngine.Initialize(empty_param); PlTerm t = PlTerm.PlVar(); Assert.AreEqual(PlType.PlVariable, t.PlType, "type enum"); PlEngine.PlCleanup(); }
public void t_succeed_and_fail() { Delegate d = new DelegateParameter1(odd); PlEngine.RegisterForeign(d); Assert.IsFalse(PlQuery.PlCall("odd(as)")); Assert.IsFalse(PlQuery.PlCall("odd(4)")); Assert.IsTrue(PlQuery.PlCall("odd(5)")); }