Creating `Atom`s
Closed this issue · 4 comments
We're using the rust clingo bindings to generate grounded programs that we would then like to solve with a few facts added as assumptions. the assumptions
argument of Control::solve
seems like the way to go, but I can't find any way to generate a Literal
or Atom
, from a Symbol
or otherwise. I would greatly appreciate any advice :)
I think the best way would be to use the ProgramBuilder for that.
...
let mut ctl = Control::new(options).expect("Failed creating Control.");
let mut builder = ast::ProgramBuilder::from(self.control).unwrap();
let sym = Symbol::create_id("test", true).unwrap();
let term = Term::from(sym);
let lit = ast::Literal::from_term(Sign::None, &term);
let hlit = HeadLiteral::from(&lit);
let rule = Rule::new(hlit, &[]);
let stmt = rule.ast_statement();
// add the rewritten statement to the program
builder
.add(&stmt)
.expect("Failed to add statement to ProgramBuilder.");
Also see the ast example.
I'm guessing i'd need to ground the program again afterwards? Sorry for these naive questions, I'm not really familiar with clingo yet^^'
Yes ProgramBuilder
is used before grounding. After grounding you could get the SymbolicAtoms
and then use the method literal()
.
Also see the symbolic atoms example.
Thanks for clearing up my confusion :) I’m going to close this, since it’s not an issue with the library :)