How to use the problog.logic.Constant function in problog

To help you get started, we’ve selected a few problog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thiagopbueno / mdp-problog / tests / test_fluent.py View on Github external
def test_state_space(self):
        running = Term('running')
        fluents = [ running.with_args(Constant('c%d' % i), Constant(0)) for i in range(1, 4) ]
        states = StateSpace(fluents)
        for i, state in enumerate(states):
            self.assertEqual(len(state), 3)
            n = 0
            for j, (fluent, value) in enumerate(state.items()):
                self.assertEqual(fluent.functor, 'running')
                self.assertEqual(fluent.args[0], 'c%d' % (j + 1))
                self.assertEqual(fluent.args[-1], 0)
                n += value * (2**j)
            self.assertEqual(n, i)
github thiagopbueno / mdp-problog / tests / test_fluent.py View on Github external
def test_action_space(self):
        reboot = Term('reboot')
        computers = [ Constant('c%i' % i) for i in range(1, 4) ]
        fluents = [ reboot(c) for c in computers ]
        fluents.append(reboot(Constant('none')))
        actions = ActionSpace(fluents)
        for i, action in enumerate(actions):
            self.assertEqual(sum(action.values()), 1)
            for j, (fluent, value) in enumerate(action.items()):
                self.assertEqual(fluent, fluents[j])
                if j == i:
                    self.assertEqual(value, 1)
                else:
                    self.assertEqual(value, 0)
github thiagopbueno / mdp-problog / tests / test_fluent.py View on Github external
def test_action_space(self):
        reboot = Term('reboot')
        computers = [ Constant('c%i' % i) for i in range(1, 4) ]
        fluents = [ reboot(c) for c in computers ]
        fluents.append(reboot(Constant('none')))
        actions = ActionSpace(fluents)
        for i, action in enumerate(actions):
            self.assertEqual(sum(action.values()), 1)
            for j, (fluent, value) in enumerate(action.items()):
                self.assertEqual(fluent, fluents[j])
                if j == i:
                    self.assertEqual(value, 1)
                else:
                    self.assertEqual(value, 0)
github thiagopbueno / mdp-problog / tests / test_engine.py View on Github external
def test_add_assignment(self):
        engine = self.engines['sysadmin']
        fluents = engine.declarations('state_fluent')
        for i in range(2**len(fluents)):
            state = Term('__s%d__' % i)
            value = (-1)**(i % 2) * 10.0*i
            node = engine.add_assignment(state, value)
            fact = engine.get_fact(node)
            self.assertEqual(fact.functor, 'utility')
            self.assertEqual(fact.args, (state, Constant(value)))
github thiagopbueno / mdp-problog / mdp-problog.py View on Github external
n = len(self._next_state_atoms)
		valuation = [0]*n
		for i in range(2**n):
			body_atoms = []
			for pos in range(n):
				if valuation[pos] == 1:
					body_atoms.append(self._next_state_atoms[pos])
				else:
					body_atoms.append(~self._next_state_atoms[pos])
			body = And.from_list(body_atoms)
			head = Term('__s{}__'.format(i))
			self._value_function_atoms.append(head)
			rule = head << body
			self._db.add_clause(rule)

			value = Term('utility', head.with_probability(None), Constant(0.0))
			self._db.add_fact(value)

			MDPProbLog.next_valuation(valuation)
github thiagopbueno / mdp-problog / mdp-problog.py View on Github external
def _build_state_atoms(self):
		state_vars = [p[0] for p in self._eng.query(self._db, Term('state_fluent', None))]
		self._state_functors = set()
		self._next_state_atoms = []
		self._current_state_atoms = []
		for t in state_vars:
			self._state_functors.add(t.functor)

			args = t.args + (Constant(1),)
			self._next_state_atoms.append(t.with_args(*args))

			args = t.args + (Constant(0),)
			curr_state_atom = t.with_args(*args)
			self._current_state_atoms.append(curr_state_atom)
			self._db.add_fact(curr_state_atom.with_probability(Term('?')))
github thiagopbueno / mdp-problog / mdpproblog / fluent.py View on Github external
def create_fluent(cls, term, timestep):
        """"
        Return a new fluent made from `term` with given `timestep`.

        :param term: any problog term
        :type term: problog.logic.Term
        :param timestep: timestep numeric value
        :type timestep: int
        :rtype: problog.logic.Term
        """
        args = term.args + (Constant(timestep),)
        return term.with_args(*args)