3232/// - parameter lcv: SHould it use the lcv heuristic to try to improve performance (default false) NOT IMPLEMENTED YET
3333/// - parameter mac3: SHould it use the mac3 heuristic to try to improve performance (default false) NOT IMPLEMENTED YET
3434/// - returns: the assignment (solution), or nil if none can be found
35- public func backtrackingSearch< V, D> ( _ csp: CSP < V , D > , assignment: Dictionary < V , D > = Dictionary < V , D > ( ) , mrv: Bool = false , lcv: Bool = false , mac3: Bool = false ) -> Dictionary < V , D > ?
35+ public func backtrackingSearch< V, D> ( csp: CSP < V , D > , assignment: Dictionary < V , D > = Dictionary < V , D > ( ) , mrv: Bool = false , lcv: Bool = false , mac3: Bool = false ) -> Dictionary < V , D > ?
3636{
3737 // assignment is complete if it has as many assignments as there are variables
3838 if assignment. count == csp. variables. count { return assignment }
3939
4040 // get a var to assign
41- let variable = selectUnassignedVariable ( csp, assignment: assignment, mrv: mrv)
41+ let variable = selectUnassignedVariable ( csp: csp , assignment: assignment, mrv: mrv)
4242
4343 // get the domain of it and try each value in the domain
44- for value in orderDomainValues ( variable, assignment: assignment, csp: csp, lcv: lcv) {
44+ for value in orderDomainValues ( variable: variable , assignment: assignment, csp: csp, lcv: lcv) {
4545
4646 // if the value is consistent with the current assignment we continue
4747 var localAssignment = assignment
4848 localAssignment [ variable] = value
4949 //println(assignment)
50- if isConsistent ( variable, value: value, assignment: localAssignment, csp: csp) {
50+ if isConsistent ( variable: variable , value: value, assignment: localAssignment, csp: csp) {
5151 //println("Found \(variable) with value \(value) and other assignment \(assignment) consistent")
5252
5353 // do inferencing if we have that turned on
@@ -62,7 +62,7 @@ public func backtrackingSearch<V, D>(_ csp: CSP<V, D>, assignment: Dictionary<V,
6262
6363 if (result != False) return result; */
6464 } else {
65- if let result = backtrackingSearch ( csp, assignment: localAssignment, mrv: mrv, mac3: mac3, lcv: lcv) {
65+ if let result = backtrackingSearch ( csp: csp , assignment: localAssignment, mrv: mrv, mac3: mac3, lcv: lcv) {
6666 return result
6767 }
6868 }
@@ -75,9 +75,9 @@ public func backtrackingSearch<V, D>(_ csp: CSP<V, D>, assignment: Dictionary<V,
7575}
7676
7777/// check if the value assignment is consistent by checking all constraints of the variable
78- func isConsistent< V, D> ( _ variable: V , value: D , assignment: Dictionary < V , D > , csp: CSP < V , D > ) -> Bool {
78+ func isConsistent< V, D> ( variable: V , value: D , assignment: Dictionary < V , D > , csp: CSP < V , D > ) -> Bool {
7979 for constraint in csp. constraints [ variable] ! { //assume there are constraints for every variable
80- if !constraint. isSatisfied ( assignment) {
80+ if !constraint. isSatisfied ( assignment: assignment ) {
8181 return false
8282 }
8383 }
@@ -86,7 +86,7 @@ func isConsistent<V, D>(_ variable: V, value: D, assignment: Dictionary<V, D>, c
8686
8787/// Return an unassigned variable - we may want to use some logic here to return the
8888/// minimum-remaining values
89- func selectUnassignedVariable< V, D> ( _ csp: CSP < V , D > , assignment: Dictionary < V , D > , mrv: Bool ) -> V {
89+ func selectUnassignedVariable< V, D> ( csp: CSP < V , D > , assignment: Dictionary < V , D > , mrv: Bool ) -> V {
9090 // do we want to use the mrv heuristic
9191 if ( mrv) {
9292 //get the one with the biggest domain
@@ -109,7 +109,7 @@ func selectUnassignedVariable<V, D>(_ csp: CSP<V, D>, assignment: Dictionary<V,
109109}
110110
111111/// get the domain variables in a good order
112- func orderDomainValues< V, D> ( _ variable: V , assignment: Dictionary < V , D > , csp: CSP < V , D > , lcv: Bool ) -> [ D ] {
112+ func orderDomainValues< V, D> ( variable: V , assignment: Dictionary < V , D > , csp: CSP < V , D > , lcv: Bool ) -> [ D ] {
113113 return csp. domains [ variable] ! //asume there is a domain for every variable
114114 /*if lcv { //not implemented yet
115115 /*// currently works only for binary constraints
0 commit comments