## 5 Building the CSP
### Creating Domains and the Constraint List  
Before the actual handling of the input data can take place, the initial variable declarations need to be done in VBA (Appendix A, row 1 to 21). Beside the dictionaries for the eight domains, two additional dictionaries _dict_SlotsORI_ (for original) and _dict_BricksORI_ are declared. These domain masters are intended as reference objects to be written in the blackboard of the configuration system. E.g., if a domain needs to be reset when the user changes his or her selection, the domain master is copied in the respecting domain and all constraints are to be regenerated without reobtaining data from the spreadsheet.  
Furthermore, the dictionaries _dict_ConList_ and _dict_ConQue_ are declared for constraint handling. The first is meant as a reference list containing all constraints, the second is the actual queue. Finally, a global counter is declared, which is needed for the template constraint and global strings as the internal working memory for assigned domain values.  
Additionally, as part of the variable declaration, three public class modules _iComponent_Bricks_, _iComponent_Slots_ and _iConstraint_ are introduced as follows in Figure 8. The first two define the domains and their properties, which are translated to the columns of the dictionaries later. The last class module is the generalized constraint variable. The dictionaries _ConArg1_... _ConArg4_ represent domains that are connected to a constraint, the strings formalize value assignments. This is, e.g., necessary for the template configurations where these arguments contain the four colors. Additionally, the string _ConExpr_ contains the type of the constraint, _ConDir_, whether it is unary or binary.  
The subroutine for reading the inventory and creating the blackboard is shown in Appendix A, row 62 to 76. Beside the path to the spreadsheet, it basically contains three functions that address the single workbooks. Note that the path to the repository in row 62 needs to be adjusted to the path where the repository is locally saved.  
The generation of the domains can be found in Appendix A, row 79 to 109 for the slots and row 112 to 143 for the bricks. In the first part of both routines, the domain master is created. Basically, it adds each row from row two on (first row is the column headline) of the spreadsheet to the dictionary. Thereby, _ArticleID_ is a temporary variable which contains the key for the dictionary. Reading the spreadsheet ends when an empty cell in the first column of the spreadsheet is reached. After the reference is created, it is distributed to the four respecting domains as the initial solution set.  
Populating the constraint reference list works similar, as shown in Appendix A, row 145 to 271. The key is realized as a counter. In order to couple domains with equality and inequality constraints (Appendix A, row 154 to 249), the involved domains need to be declared as arguments. As VBA does not allow to compose variable names out of,  
Figure 7: Spreadsheet constraint definition.  
e.g., a combination of strings and numeric values at runtime, the strings obtained from the spreadsheet once need to be related to the dictionaries. Therefore, the select case expressions contain the corresponding assignments for the constraint arguments. Additionally to the dictionaries, the arguments are also stored as strings for further processing. If the constraint is binary, a second constraint with opposite arguments is created.  
If the spreadsheet contains a constraint with the expression _Obligation_, the four arguments of the corresponding entry in the constraint list are populated with the four colors as shown in Appendix A, row 251 to 271.