NQueens - ListIterator var2_iterator =...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
package CSP; /** * Title: NQueens * Description: Class for NQueens CSP. * Copyright: Copyright (c) 2005 * Company: MIT * @author Andreas Hofmann * @version 1.0 */ import java.util.*; public class NQueens extends CSP_rep { int size = 0; public NQueens(int sz) { size = sz; } public void initialize() { // Initialize NQueens problem according to size. // Initialize variables and domains. variables = new ArrayList(); domain = new NQueensDomain(size); constraints = new ArrayList(); for (int col=0; col<size; col++) { NQueensDomain var_domain = new NQueensDomain(size); NQueensVariable new_var = new NQueensVariable(col, var_domain); variables.add(new_var); } // Initialize constraints. ListIterator var1_iterator = variables.listIterator(); while (var1_iterator.hasNext()) { NQueensVariable var1 = (NQueensVariable)var1_iterator.next();
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ListIterator var2_iterator = variables.listIterator(); while (var2_iterator.hasNext()) { NQueensVariable var2 = (NQueensVariable)var2_iterator.next(); if (var1 != var2) constraints.add(new NQueensConstraint(var1, var2)); } } } public void print() { ListIterator var_iterator = variables.listIterator(); while (var_iterator.hasNext()) { NQueensVariable current_var = (NQueensVariable)var_iterator.next(); System.out.println("col " + current_var.col); List values = current_var.domain.domain_values; ListIterator val_iterator = values.listIterator(); System.out.println("rows: "); while (val_iterator.hasNext()) { Integer current_val = (Integer)val_iterator.next(); System.out.print(" " + current_val); } System.out.println(); } } }...
View Full Document

  • Fall '05
  • BrianWilliams
  • According to Jim, Andreas Hofmann, NQueensDomain(size);, public void initialize, Initialize NQueens problem

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern