I'm working on a solution using the SbsSW.SwiPlCs dll for integration between a C# application and a prolog .pl source file, however I'm facing a problem with the assert(atom) command.
My prolog file is a set of airports and flights between airports, during my running time I assert new airports and flights like this:
internal void alta(Flight new)
{
try
{
PlEngine.Initialize(new string[] { "" });
//PlEngine.Initialize(param);
PlQuery.PlCall("consult(vuelos)");
//comando
//flight(v01,bra,ams,1000)
PlQuery q = new PlQuery("assert(fligth(" + new.id + "," + new.airportFrom.id + "," + new.airportTo.id + "," + new.price + "))");
}
catch (PlException e)
{
Console.WriteLine(e.MessagePl);
Console.WriteLine(e.Message);
}
finally
{
PlEngine.PlCleanup();
}
}
This runs fine, and I don't get any error message nor exceptions (I used to get one, but it was because my flight/4 and airport/2 statements were static, I changed both to dynamic at the beggining of my file and no errors were thrown).
My problem is when I try to consult something involving the new asserts I got at runtime.
internal List<string> directFlight(Airport from, Airport to)
{
List<string> list = new List<string>();
try
{
PlEngine.Initialize(new string[] { "" });
//PlEngine.Initialize(param);
PlQuery.PlCall("consult(vuelos)");
//comando
//una_escala(W,from,to)
using (PlQuery q = new PlQuery("directF(W," + from.id + "," + to.id + ")"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
{
list.Add(v["W"].ToString());
}
}
}
catch (PlException e)
{
Console.WriteLine(e.MessagePl);
Console.WriteLine(e.Message);
}
finally
{
PlEngine.PlCleanup();
}
return list;
}
My List<string> list variable should return the list of all the flight id's which go from from to to, and this works with pre-loaded flights (the ones on my vuelos.pl which I call on PlQuery.PlCall("consult(vuelos)");), but I doesn't take into account any of my new flights created at runtime and I can't figure out why.