Question
Having no idea how to start to write 3 sat problem in c++ Can anyone give me a little help 2 Project For this project
Having no idea how to start to write 3 sat problem in c++ Can anyone give me a little help
2 Project
For this project you will be writing a 3SAT generator, that can also test given truth values. That is, the goal of this program is to create a general 3SAT problem with at most 10 variables and 10 clauses. Your program will then print this logical expression so the user can see it (you will use as opposed to ) and then ask the user for truth values for each of the variables. Then it will test whether those truth values make the whole expression TRUE or not. If they do make the expression TRUE, you should inform the user. If they do not, you again inform the user AND print the clause which is invalid.
3 Expectations
Each run of the program should randomly choose the number of possible variables (between 3 and 10 variables is allowed) it should also randomly choose the number of clauses (between 1 and 10 is allowed). Within a clause, a variable should not be repeated, ever. That is, (x1x1x2) is not a valid clause, neither is (x2x2x3). But of course variables can be repeated between other clauses. After choosing the number of variables and clauses, each clause should be generated randomly. You may represent this generation anyway that you like. The standard way to represent a clause is to use a list (in Python) or an int[] in C++. For example: (x1 x2 x3) can be represented as [1,2,3], and (x2 x1 x5) can be represented as [-2,1,-5], that is, negative numbers represent a negated variable. One way to randomly generate clauses is for each clause randomly choose a number between 1 and the number of variables. This selects your xk, then you should also randomly decide whether or not to negate this variable, you can do this as a 50/50 chance. After randomly generating all of the clauses, your program should print this clause to the screen. Since you cannot directly print you will use as an alternative. Similarly subscripts are not possible, so you will just place numbers next to an x. You will print something like this: ( x5 x2 x1) (x2 x5 x6) ( x8 x1 x3) (x9 x7 x4) That is, you MUST print parentheses and and , use v and for these (it will, ironically, look better printed by your program than by LATEX). After printing the expression you will ask the user for T/F values for each variable. You MUST ensure input is correct! If I enter: s, (instead of T/F) then you should ask again until I successfully choose T/F. However you should allow upper OR lower case, that is, valid inputs are T,t,F,f. Any other inputs are to be ignored and you should re-ask. After asking for user input for EVERY variable, you should evaluate whether the values that were given do or do not satisfy the generated expression. Then you should inform the user whether they were correct or not, you may use any message you like to inform the user. But if they were incorrect you MUST 2 also print the clause that is evaluated to FALSE (and ONLY that clause). It is possible that many clauses fail, you should print the FIRST clause which fails. You should not use any external libraries to evaluate the 3SAT expression. There are many 3SAT solvers in most languages, you should not use these. Programs that do use them will be penalized, harshly. Keep in mind the goal of this project is not to solve a 3SAT expression, but to generate one, and verify a given solution
This is a example result
./Projectl Please enter a value T/F for variable x1: t Please enter a value T/F for variable x2: F Please enter a value T/F for variable x3: F Please enter a value T/F for variable x4:T Please enter a value T/F for variable x5:T Please enter a value T/F for variable x6: F Please enter a value T/F for variable x7:F This assignment is false, due to the clauseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started