Skip to content

Commit

Permalink
only one full encodinge per solver. refactored code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrueh committed Jun 5, 2024
1 parent f2d016d commit 75713ff
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/coomsolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
log = get_logger("main")

SOLVERS = ["clingo", "fclingo"]
COOM_PROFILES = ["core", "partonomy", "numeric", "all"]


def convert_instance(coom_file: str, output_dir: Optional[str] = None) -> str: # nocoverage
Expand Down
2 changes: 1 addition & 1 deletion src/coomsolver/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main():
with TemporaryDirectory() as temp_dir:
output_lp_file = convert_instance(args.input, temp_dir)
clingo_main(
COOMApp(solver=args.solver, profile=args.profile, output=args.output, show=args.show),
COOMApp(solver=args.solver, output=args.output, show=args.show),
[output_lp_file] + unknown_args,
)

Expand Down
5 changes: 1 addition & 4 deletions src/coomsolver/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class COOMApp(Application):
"""

_solver: str
_profile: str
_output: str
_show: bool
_istest: bool
Expand All @@ -70,7 +69,6 @@ def __init__(
self,
log_level: str = "",
solver: str = "",
profile: str = "",
output: str = "",
show: bool = False,
istest: bool = False,
Expand All @@ -79,7 +77,6 @@ def __init__(
Create application.
"""
self._solver = "clingo" if solver == "" else solver
self._profile = profile
self._output = "asp" if output == "" else output
self._show = show
self._istest = istest
Expand Down Expand Up @@ -181,7 +178,7 @@ def main(self, control: Control, files: Sequence[str]) -> None:
if self._show:
print("\n".join(processed_facts)) # nocoverage
else:
encoding = get_encoding(f"{self._solver}-{self._profile}.lp")
encoding = get_encoding(f"encoding-{self._solver}.lp")
facts = "".join(processed_facts)
if self._solver == "clingo":

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
% #include "clingo-core.lp".
% #include "base/partonomy.lp".
% #include "base/numeric.lp".

#include "base/defined.lp".
#include "base/auxiliary.lp".

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
% #include "fclingo-core.lp".
% #include "base/partonomy.lp".
% #include "base/numeric-fclingo.lp".

#include "base/defined.lp".
#include "base/auxiliary-fclingo.lp".

Expand Down
8 changes: 4 additions & 4 deletions src/coomsolver/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from textwrap import dedent
from typing import Any, Optional, cast

from coomsolver import COOM_PROFILES, SOLVERS
from coomsolver import SOLVERS

from . import logging

Expand Down Expand Up @@ -90,9 +90,9 @@ def get(levels: list[tuple[str, int]], name: str) -> Optional[int]:
)
parser_solve.add_argument("--solver", "-s", type=str, help="Set solver", choices=SOLVERS, default="clingo")

parser_solve.add_argument(
"--profile", "-p", type=str, help="Set COOM profile", choices=COOM_PROFILES, default="all"
)
# parser_solve.add_argument(
# "--profile", "-p", type=str, help="Set COOM profile", choices=COOM_PROFILES, default="all"
# )

parser_solve.add_argument(
"--output", "-o", type=str, help="Set console output format", choices=["asp", "coom"], default="asp"
Expand Down
14 changes: 7 additions & 7 deletions tests/test_sanity_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ def test_product(self) -> None:
Test solving an empty product (root structure).
"""
program = 'structure("product").'
run_test(deepcopy(TEST_EMPTY), program=program, profile="core")
run_test(deepcopy(TEST_EMPTY), program=program)

def test_no_product(self) -> None:
"""
Test solving programs without program (root structure).
"""

program_feature = 'feature("product","a","b",1,1).'
run_test(deepcopy(TEST_EMPTY), program=program_feature, profile="core")
run_test(deepcopy(TEST_EMPTY), program=program_feature)

program_enum_attr = """
coom_enumeration("a").
coom_attribute("a","b","num").
coom_option("a", "a1").
coom_attribute_value("a","a1","b",1)."""
run_test(deepcopy(TEST_EMPTY), program=program_enum_attr, profile="core")
run_test(deepcopy(TEST_EMPTY), program=program_enum_attr)

def test_no_feature(self) -> None:
"""
Expand All @@ -47,7 +47,7 @@ def test_no_feature(self) -> None:
coom_enumeration("a").
coom_option("a","a1").
coom_option("a","a2")."""
run_test(deepcopy(TEST_EMPTY), program=program_no_feature, profile="core")
run_test(deepcopy(TEST_EMPTY), program=program_no_feature)

def test_undef(self) -> None:
"""
Expand All @@ -61,7 +61,7 @@ def test_undef(self) -> None:
coom_binary("color=Silver","color","=","Silver").
coom_path("color",0,"color").
coom_constant("Silver")."""
run_test(deepcopy(TEST_EMPTY), program=program_require, profile="core")
run_test(deepcopy(TEST_EMPTY), program=program_require)

program_condition = """
coom_structure("product").
Expand All @@ -75,7 +75,7 @@ def test_undef(self) -> None:
coom_binary("size=Big","size","=","Big").
coom_path("size",0,"size").
coom_constant("Big")."""
run_test(deepcopy(TEST_EMPTY), program=program_condition, profile="core")
run_test(deepcopy(TEST_EMPTY), program=program_condition)

def test_empty_combinations(self) -> None:
"""
Expand All @@ -91,4 +91,4 @@ def test_empty_combinations(self) -> None:
coom_context(0,"product").
coom_combinations(0,0,"a").
coom_path("a",0,"a")."""
run_test(deepcopy(TEST_UNSAT), program=program, profile="core")
run_test(deepcopy(TEST_UNSAT), program=program)
8 changes: 4 additions & 4 deletions tests/test_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run_test(self, test_name: str) -> None:
"files" (List[str] or "program" (str)
"""
test, program, files = unpack_test(test_name)
run_test(test, files=files, program=program, ctl_args=["0"], solver="clingo", profile="core")
run_test(test, files=files, program=program, ctl_args=["0"], solver="clingo")

def test_require(self) -> None:
"""
Expand Down Expand Up @@ -97,7 +97,7 @@ def run_test(self, test_name: str) -> None:
"ftest" (Optional[clintest.Test]): A clintest for fclingo
"""
test, program, files = unpack_test(test_name, fclingo=True)
run_test(test, files=files, program=program, ctl_args=["0"], solver="fclingo", profile="core")
run_test(test, files=files, program=program, ctl_args=["0"], solver="fclingo")

def test_require(self) -> None:
"""
Expand Down Expand Up @@ -149,7 +149,7 @@ def run_test(self, test_name: str) -> None:
"files" (List[str] or "program" (str)
"""
test, program, files = unpack_test(test_name)
run_test(test, files=files, program=program, ctl_args=["0"], solver="clingo", profile="partonomy")
run_test(test, files=files, program=program, ctl_args=["0"], solver="clingo")

def test_structure(self) -> None:
"""
Expand Down Expand Up @@ -196,7 +196,7 @@ def run_test(self, test_name: str) -> None:
"files" (List[str] or "program" (str)
"""
test, program, files = unpack_test(test_name, fclingo=True)
run_test(test, files=files, program=program, ctl_args=["0"], solver="fclingo", profile="partonomy")
run_test(test, files=files, program=program, ctl_args=["0"], solver="fclingo")

def test_structure(self) -> None:
"""
Expand Down

0 comments on commit 75713ff

Please sign in to comment.