This assignment focuses on conjunctive normal form formulas (cnf-formula) and satisfiability.
In this assignment, you must create a Netbeans Java program that:
• prompts the user for the location of a file to load a cnf-formula (use JFileChooser)
• reads a cnf-formula from the file creating a CnfFormula object (see file-format below),
• prompt the user for a variable assignment (see AssignmentView below),
• verifies and displays whether the user’s assignment satisfies the cnf-formula,
• determines whether the cnf-formula is satisfiable and if so, output the assignment,
• as Java comments give the Big-O analysis of the verify and isSatisfiable methods,
• as a separate file, submit the cnf-formula file you “unit” tested on./*
* (c) 2018 Richard Blumenthal, All Rights Reserved
*
* Regis University students may use this code for their own
* educational purposes, but unauthorized duplication or
* distribution withour the author’s consent is both a copyright
* and honor code violation.
*/
package edu.regis.cs475.gui;

import edu.regis.cs475.domain.Assignment;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

/**
* An editable view of an Assignment model.
*
* @author rickb
*/
public class AssignmentView extends JDialog
implements ActionListener, WindowListener {

/**
* The Assignment model displayed in this view
*/
private Assignment model;

/**
* Assignment variables and their values are displayed in this table
*/
private JTable table;
private MyTableModel tableModel;

private JButton okBut;

public AssignmentView() {
super((JFrame) null, “Select an Assignment”, true);

setModal(true);

initComponents();
initLayout();

addWindowListener(this);
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

pack();
}

/**
* Return the Assignment model displayed in this view
*
* @return an Assignment (only updated if Ok was previously selected)
*/
public Assignment getModel() {
// updateModel
return model;
}

/**
* Display the given model in this view
*
* @param model an Assignment
*/
public void setModel(Assignment model){
this.model = model;

updateDisplay();
}

/**
* Create the primary child components used in this view
*/
private void initComponents() {
Object[][] data = {{“x1”, new Boolean(false)}};

tableModel = new MyTableModel(data);

table = new JTable(tableModel);

okBut = new JButton(“OK”);
okBut.addActionListener(this);
}

/**
* Layout the child components used in this view
*/
private void initLayout() {
GPanel panel = new GPanel();

JScrollPane scroller = new JScrollPane(table);

JLabel label = new JLabel(“Please select values for the variables”);

panel.addc(label, 0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
5,10,0,10);

panel.addc(scroller, 0, 1, 1, 1, 1.0, 1.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
5,10,0,10);

paThis assignment focuses on conjunctive normal form formulas (cnf-formula) and satisfiability.

In this assignment, you must create a Netbeans Java program that:

• prompts the user for the location of a file to load a cnf-formula (use JFileChooser)

• reads a cnf-formula from the file creating a CnfFormula object (see file-format below),

• prompt the user for a variable assignment (see AssignmentView below),

• verifies and displays whether the user’s assignment satisfies the cnf-formula,

• determines whether the cnf-formula is satisfiable and if so, output the assignment,

• as Java comments give the Big-O analysis of the verify and isSatisfiable methods,

• as a separate file, submit the cnf-formula file you “unit” tested on.

Input File Format

Consider the cnf-formula,

( 1 ∨ 3 ∨ 4) ∧ (�̅�1 ∨ 3) ∧ (�̅�1 ∨ 4 ∨ �̅�2) ∧ �̅�3 ∧ ( 2 ∨ �̅�4)

This cnf-formula is represented as one line in the input file,

(x1 v x3 v x4) ^ (nx1 v x3) ^ (nx1 v x4 v nx2) ^ nx3 ^ (x2 v nx4)

The general format of this cnf-formula in the input file is:

1 ^ 2^ … ^

Where each clause in the cnf-formula is separated by a caret ‘^’ character. A clause is either a literal

or a disjunction of literals surrounded by where a letter ‘v’ is used to separate multiple literals.

1 v 2 v … v

A literal is either a variable name or a negated variable, in which case the variable name is

preceded by the letter ‘n’ (Naturally, n’s and v’s cannot be used in a variable name.)

Class Diagram

Minimally, your program must implement the following UML class diagram (notes follow).

CnfFormula and Clause

• literals() – return the variable names (i.e. literals) used in this formula/clause

• verify(Assignment) – return true, if the truth assignments for the variables in the

Assignment satisfy this formula/clause

SatNpApp

• verify(Assignment) – utility method that sends a verify message to a CnfFormula

• isSatisfied() – utility method that finds an assignment, if any, that satisfies the current

CnfFormula

Here’s one way to implement the main(…) method in the SatNpApp:

view = new AssignmentView();

File file = chooseExprLocation();

try {

CnfFormula formula = loadCnfFormula(file);

do {

Assignment assignment = new Assignment(formula);

view.setModel(assignment);

view.setVisible(true);

if (expr.verify(assignment)) {

JOptionPane.showMessageDialog(null, “Satisfied”);

} else {

JOptionPane.showMessageDialog(null, “Not Satisfied”);

}

isSatisfiable(formula);

} while (trueFalsePrompt(“Test another input string?”));

AssignmentView

The AssignmentView class is given in the online shell for this Topic. It can be used to easily assign

the truth values for an assignment. It is implemented using the model, view, controller design

pattern in which an Assignment object is the model.

This is an individual assignment. If you have questions email the faculty (don’t post in the forum).

S/*
* (C) 2002 Richard Blumenthal, All rights reserved
* Regis University students are free to use this code for their own
* education purposes. Unauthorized duplication or distribution
* without the author’s permission is strictly forbidden.
*/
package edu.regis.cs475.gui;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JPanel;

/**
* A utility JPanel with a GridBagLayout and a convenience addc method.
*
* @author Rickb
*/
public class GPanel extends JPanel {
/**
* Initialize this panel with a GridBagLayout.
*/
public GPanel() {
setLayout(new GridBagLayout());
}

/**
* Add components to this panel using the given constraints.
* For example,

* addc(this, JComponent, 0,0, 1,1, 1.0,1.0,

*    GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
*    5,5,5,5);
* @param panel the Panel with a GridBagLayout owning the child component
* @param c the child component
* @param gridX the row in which the child component is anchored
* @param gridY the column in which the child component is anchored
* @param gridWidth the rows spanned by the child component in the bag
* @param gridHeight the cols spanned by the child component in the bag
* @param weightx the amount of width scaling during panel expansion
* @param weighty the amount of height scaling during panel expansion
* @param anchor a GridBagConstraints anchor, e.g. NORTHWEST
* @param fill a GridBagConstraints fill, e.g. HORIZONTAL
* @param top padding added to the inset for the child
* @param left padding added to the inset for the child
* @param bottom padding added to the inset for the child
* @param right padding added to the inset for the child
*/
public void addc(Component c,
int gridX, int gridY,
int gridWidth, int gridHeight,
double weightx, double weighty,
int anchor, int fill,
int top, int left, int bottom, int right) {

Insets insets = new Insets(top, left, bottom, right);

GridBagConstraints cnstr = new GridBagConstraints(gridX,
gridY,
gridWidth,
gridHeight,
weightx,
weighty,
anchor,
fill,
insets,
0,
0);

GridBagLayout l = (GridBagLayout) getLayout();
l.setConstraints(c, cnstr);

add(c);
}
}




Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.