-
I have this directory: .
├── facts
│ └── edge.facts
├── test.cpp
├── test_souffle.dl The contents of which are:
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
#include <souffle/SouffleInterface.h>
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
using namespace std::chrono;
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " <datalog_file> <facts_file>" << std::endl;
return 1;
}
const std::string datalogFile = argv[1];
std::cout << "Datalog file: " << datalogFile << std::endl;
const std::string factsFile = argv[2];
std::cout << "Facts file: " << factsFile << std::endl;
// Initialize Souffle program
souffle::SouffleProgram *prog = souffle::ProgramFactory::newInstance(datalogFile);
if (prog == nullptr)
{
std::cerr << "Could not create Souffle program instance." << std::endl;
return 1;
}
// Load facts from file
prog->loadAll(factsFile);
// Run the program
prog->run();
// Retrieve relation "path" which contains the results of transitive closure
souffle::Relation *path = prog->getRelation("path");
if (path == nullptr)
{
std::cerr << "Relation 'path' not found." << std::endl;
return 1;
}
// Iterate over the tuples in the relation
for (auto &tuple : *path)
{
int start, end;
tuple >> start >> end;
std::cout << "Path: " << start << " -> " << end << std::endl;
}
// Cleanup
delete prog;
return 0;
}
.decl edge(x: number, y: number)
.input edge
.decl path(x: number, y: number)
.output path
path(x, y) :- edge(x, y).
path(x, y) :- path(x, z), edge(z, y). When I issue the following command in my terminal: souffle-compile.py test.cpp -o souffle_tmp
It compiles and ./souffle_tmp ./test_souffle.dl ./facts/edge.facts or ./souffle_tmp test_souffle.dl facts/edge.facts I get this error: Datalog file: test_souffle.dl
Facts file: facts/edge.facts
Could not create Souffle program instance. What I can think of is that the souffle instance could not be created. Is something wrong with my code or something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
Hi,
newInstance
does not take a datalog file name, it takes the name of a soufflé program (look at the generated c++ to get the exact identifier).