File: module.py

package info (click to toggle)
gringo 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,128 kB
  • sloc: cpp: 210,867; ansic: 37,507; python: 11,271; yacc: 825; javascript: 627; sh: 368; xml: 364; makefile: 102
file content (37 lines) | stat: -rw-r--r-- 763 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Example showing basic clingo usage of the clingo module.
"""

from typing import Iterator

from clingo.control import Control
from clingo.symbol import Number, Symbol


class ExampleApp:
    """
    Example application class.
    """

    @staticmethod
    def divisors(sym: Symbol) -> Iterator[Symbol]:
        """
        Return all divisors of the given number.
        """
        num = sym.number
        for i in range(1, num + 1):
            if num % i == 0:
                yield Number(i)

    def run(self):
        """
        Runs the example.
        """
        ctl = Control()
        ctl.load("example.lp")
        ctl.ground([("base", [])], context=self)
        ctl.solve(on_model=print)


if __name__ == "__main__":
    ExampleApp().run()