Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_string #113

Open
yoni206 opened this issue Sep 11, 2022 · 8 comments
Open

to_string #113

yoni206 opened this issue Sep 11, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@yoni206
Copy link

yoni206 commented Sep 11, 2022

It would be great to have a way of pretty-printing formulas, by providing a dictionary between the variables (numerals) and application-specific name. This is easy to do for ordinary CNF using dictionaries, but I am not sure how to do this for pseudo-Boolean constraints. This would be nice to have for debugging applications that use pysat.

@alexeyignatiev
Copy link
Collaborator

Good point, @yoni206. But what do you mean by "application-specific name"? The standard (and most straightforward) way to implement formula's __str__() is to make it return its DIMACS representation.

@yoni206
Copy link
Author

yoni206 commented Sep 14, 2022 via email

@alexeyignatiev
Copy link
Collaborator

Have a look at the functionality of IDPool. It is meant to represent this kind of dictionary.

@RexYuan
Copy link
Contributor

RexYuan commented May 11, 2023

@yoni206 do you mean that, for ordinary CNF, given clauses

[
  [1, -2, 3],
  [2, -3]
]

and dictionary

{
  1: "a",
  2: "b",
  3: "c"
}

you want to print out something like this?

(a | ~b | c) & (b | ~c)

@alexeyignatiev
Copy link
Collaborator

I guess this string may help a non-SAT researcher understand the meaning of the formula but a SAT practitioner would perhaps prefer a formula in DIMACS. It has been a standard for many years and everybody speaks this "language". What I meant above was that the mapping from integer variable identifiers to the corresponding objects can be provided by means of the already existing IDPool. I presume it can be added into comments line sitting in a CNF object.

@yoni206
Copy link
Author

yoni206 commented May 11, 2023

@RexYuan yes, but also for cardinality constraints.

@RexYuan
Copy link
Contributor

RexYuan commented May 11, 2023

@yoni206 How about using two dictionaries like this?

card_clauses = [
  [[1, -2, 3], 2],
  [[2, -3], 1]
]
card_names = {
  2: "n",
  1: "m"
}
var_names = {
  1: "a",
  2: "b",
  3: "c"
}

then you have

a + ~b + c <= n
b + ~c <= m

Of course, this would run into a problem if there are different names for a cardinality, but I think then they are already indistinguishable on the constraint level.

@yoni206
Copy link
Author

yoni206 commented May 12, 2023

yeah that could work

@alexeyignatiev alexeyignatiev added the enhancement New feature or request label Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants