This predicate picks one domain variable in Vars based on some selection criterion. The selected entry is returned in X. Vars is either a collection of domain variables (Arg is 0), or terms containing domain variables (in which case the domain variable is in the Arg'th argument of each term).
This predicate provides similar functionality as delete/5, but is more efficient and specific to GFD, and Select cannot be a user- defined method. This predicate is more efficient than delete/5 because the variable selection is done by a single low-level procedure. Unlike delete/5, which does the selection at the ECLiPSe level, and deletes the selected element from Vars, select_var/5 can select the variable using a handle, which is a low-level representation of the variables extracted from Vars. The first time the predicate is called, select_var/5 will extract the domain variables from Vars and create the low-level handle to these variables, which is returned in Rest. The handle can then be used (in place of Vars) in subsequent calls to select_var/5, avoiding the overhead of re-analysing the variable collection.
Select is one of the following predefined selection methods: input_order, occurrence, anti_occurrence, max_weighted_degree, min_weighted_degree, max_weighted_degree_per_value, min_weighted_degree_per_value, smallest, largest, smallest_upb, largest_lwb, first_fail, anti_first_fail, most_constrained, most_constrained_per_value, least_constrained_per_value, max_regret, max_regret_lwb, min_regret_lwb, max_regret_upb.
These are essentially the same selection methods as those for search/6. The selection works by calculating the selection criterion for each variable in Vars, in the order they are in Vars, and chosing the first variable with the best value. Note that only non-instantiated variables (i.e. variable with more than 1 value in its domain) are considered. If all variables are instantiated, the predicate fails, i.e. the predicate will fail when all variables in Vars have been labelled.
% Simple labelling implemented using select_var/5 and indomain/2 labelling1(Vars, Select, Choice) :- (select_var(V, Vars, Rest, 0, Select) -> indomain(V, Choice), labelling1(Rest, Select, Choice) ; true ). % Variant using select_var/5 and try_value/2 labelling2(Vars, Select, Choice) :- (select_var(V, Vars, Rest, 0, Select) -> try_value(V, Choice), labelling2(Rest, Select, Choice) ; true ).