/*======================================================================== Copyright (C) 2006 by Geir-Tore Lindsve, Torbjørn Meistad and Yngve Raudberget, hereby refered to as "the authors". All rights reserved Permission is hereby granted, without written agreement and without license or royalty fees, to use, reproduce, prepare derivative works, distribute, and display this software and its documentation for NONCOMMERCIAL RESEARCH AND EDUCATIONAL PURPOSES, provided that (1) the above copyright notice and the following two paragraphs appear in all copies of the source code and (2) redistributions, including without limitation binaries, reproduce these notices in the supporting documentation. IN NO EVENT SHALL THE AUTHORS, OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. ========================================================================*/ using System; using System.Collections.Generic; using System.Collections; using System.Text; using Casper.Exceptions; using Casper.Data; using Casper.Algorithm.VariableOrdering; using Iesi.Collections; namespace Casper.Algorithm { /// /// Class storing the variables and domaines used by . /// public class LookaheadVariables { private Hashtable varDoms; private IVariableOrdering varOrder; /// /// Initializes a new instance of the class. /// /// The variable ordering /// The constraint graph. /// public LookaheadVariables(CspVariableOrdering varOrderType, ConstraintGraph cGraph) { this.varDoms = new Hashtable(); if (cGraph == null) this.varOrder = new StaticVarOrder(); else { try { this.varOrder = GenerateVarOrder(varOrderType, cGraph); } catch (CasperException) { throw; } } } /// /// Gets or sets the variables and domaines. /// /// The variables/domaines public Hashtable VarDoms { get { return varDoms; } set { varDoms = value; } } /// /// Gets or sets the variable ordering. /// /// The var order. public IVariableOrdering VarOrder { get { return varOrder; } set { varOrder = value; } } /// /// Gets the variable which belongs to number in queue. /// /// The number in queue. /// A variable and its domaines. public LookAheadVarDom GetVar(int numberInQueue) { if (numberInQueue >= varDoms.Count) return null; else { LookAheadVarDom var = (LookAheadVarDom)varDoms[this.varOrder.GetNextVar(numberInQueue)]; return var; } } /// /// Generetes the variable ordering. For internal use of this class. /// /// Chosen variable ordering /// The constraint graph. /// The variable ordering class. /// private IVariableOrdering GenerateVarOrder(CspVariableOrdering varOrderType, ConstraintGraph cGraph) { if(varOrderType == CspVariableOrdering.vo_static) return new StaticVarOrder(); else if (varOrderType == CspVariableOrdering.vo_minwidth) { try { return new MinimumWidthOrder(cGraph); } catch (CasperException) { throw; } } else return new StaticVarOrder(); } } }