NQueens - ListIterator var2_iterator =...

Info iconThis 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();
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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(&quot;col &quot; + current_var.col); List values = current_var.domain.domain_values; ListIterator val_iterator = values.listIterator(); System.out.println(&quot;rows: &quot;); while (val_iterator.hasNext()) { Integer current_val = (Integer)val_iterator.next(); System.out.print(&quot; &quot; + current_val); } System.out.println(); } } }...
View Full Document

Page1 / 2

NQueens - ListIterator var2_iterator =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online