A Hybrid Programming Framework for Modeling and Solving Constraint Satisfaction and Optimization Problems

This paper proposes a hybrid programming framework for modeling and solving of constraint satisfaction problems (CSPs) and constraint optimization problems (COPs). Two paradigms, CLP (constraint logic programming) and MP (mathematical programming), are integrated in the framework. The integration is supplemented with the original method of problem transformation, used in the framework as a presolving method. The transformation substantially reduces the feasible solution space. The framework automatically generates CSP and COP models based on current values of data instances, questions asked by a user, and set of predicates and facts of the problem being modeled, which altogether constitute a knowledge database for the given problem.This dynamic generation of dedicatedmodels, based on the knowledge base, together with the parameters changing externally, for example, the user’s questions, is the implementation of the autonomous search concept. The models are solved using the internal or external solvers integrated with the framework. The architecture of the framework as well as its implementation outline is also included in the paper. The effectiveness of the framework regarding the modeling and solution search is assessed through the illustrative examples relating to scheduling problems with additional constrained resources.


Introduction
Constraint satisfaction problems (CSPs) and/or constraint optimization problems (COPs) can involve the variables that take values over finite domains (integer, real, binary, etc.) and constraints of all types and characters [1].By connecting variables, constraints affect the feasible variable domain ranges.Modeling and solving of those problems make up one of the major interest areas of various computer science communities, including operation research, mathematical programming, constraint programming, and artificial intelligence.Problems with constraints like CSP and COP are frequent in production, distribution, transportation, logistics, computer networks, software engineering, project management, planning and scheduling, and so forth.One of the features resulting from the users' changeable expectations is the need to solve the problem multiple times for variable data instances and parameters.Users express their expectations by asking all kinds of questions.On the one hand, the question is related to the possibility of realizing the task with certain resources at the defined time; on the other hand, it concerns optimal parameters of task realization, and it is about the optimal configuration of the system.Quite often, the questions include logical conditions (e.g., relating to mutual exclusion, dynamic connecting of resources).Because of the changeability of the questions, parameters, and data instances, the idea of autonomous search seems to be the most suitable for solving the problems with constraints.The autonomous search should have the ability to preferably modify and change its internal components when exposed to changing external parameters, requirements, and/or data instances [2].
The underlying motivation for this study was the idea of developing a programming and implementation platform, which would allow effective modeling and solving of CSPs and COPs and solving these problems in an automatic mode (using the autonomous search) despite changes in data instances, parameters, and questions asked by users.The idea was implemented as a hybrid programming framework.To build the framework, the authors used hybridization of various programming paradigms and their own original method of transformation.In addition, the authors proposed 2 Scientific Programming a dynamic method for generating dedicated models, based on the knowledge database made up of facts, predicates, and questions asked by users.

Backgrounds, Methods, and Structures
Models for problems with constraints need environments that allow modeling and solving the constraints in an easy and effective way.Historically, operations research, in particular, mathematical programming, network programming, and dynamic programming, and so forth, has been used for this purpose.Numerous models (MIP-mixed integer programming, MILP-mixed integer linear programming, IPinteger programming, etc.), algorithms (branch and bound, symplex, branch and cost, etc.), and good practices have been developed to facilitate solving problems with constraints [3].All these methods and models, however, have some limitations concerning the character of constraints (e.g., only linear constraints) or the character of variables (e.g., only real variables), and so forth.For different types of constraints (nonlinear, logical, etc.) and/or decision variables (integer, binary, etc.), they were either inapplicable or ineffective.For the approach to be most universal and suitable, a given problem must be looked at from the perspective of variables and connecting constraints with the domains of variables taken into account.Constraint logic programming (CLP) paradigm allows this approach.Constraint logic programming (CLP) is a form of constraint programming (CP) paradigm, where logic programming is extended to include CSP (constraint satisfaction problem).CLP programs are built from valid Prolog-based logic data structures.A program is a collection of predicates, and a predicate is a collection of clauses.The idea of a clause is to define that something is true.The simplest form of a clause is the fact.For example, the following two are facts: technology (product, machine, and execution time) and vehicle (capacity, type, and cost).Syntactically, a fact is just a structure (or an atom) terminated by a full stop [4].
Each constraint Cst  binds a set of decision variables and is used to restrict domains of these variables.Solving a CSP means finding the state/condition of a problem, in which the assignment of decision variables satisfies all constraints.The general algorithm for solving a CSP is shown in Figure 1.The algorithm consists of constraint propagation and variable distribution activated in the sequence.If this sequence does not provide a result, backtracking is used and sequence activation is repeated.The algorithm is very effective for  solving the problems, in which aryness of constraints does not exceed 2. The CSP algorithm is often ineffective in the case of the problems in which constraints connect more than two decision variables and the optimization problems with constraints (COPs).The effectiveness of propagation is reduced significantly and the number of backtrackings increases.In extreme cases, the algorithm is able to neither find any feasible solution within the allowable time nor ascertain its absence.
In order to overcome this shortcoming, suggestions of integrating the CP/CLP paradigms with other paradigms occurred.Since the areas are similar, constraints and decision variables, the integration usually relates to the paradigm of mathematical programming [5][6][7][8][9].
Several scenarios of CP/CLP and MP integration have been reported in the literature [10]: (i) Double modeling uses both CP and MP models and exchanges information while solving.
(ii) Search-inference duality views CP and MP methods as special cases of a search/inference duality.
(iii) Decomposition decomposes problems into a CP part and an MP part using a Benders scheme.
In the approach proposed in this paper, the scenario for the integration of both paradigms is supplemented with the authors' own method of problem transformation [11][12][13] and the idea of autonomous search [12].All these components are connected and integrated into the programming hybrid framework (Section 3).
The method of problem transformation [11,13] proposed by authors (Section 3.2) is briefly speaking, the transformation of the search space performed by removing all points and areas in which decision variables cannot occur, thus reducing the size of this space.Transformations are usually performed through changing the problem specification and adding the transformed model (with reduced and transformed decision variables and constraints).The transformation is conducted on the basis of facts, attributes, and constraints.The idea of autonomous search (Section 3.3) is implemented through the transformation method and automatic model generation.The models are generated dynamically using adequate CLP predicates, based on the current set of input facts (data instances), knowledge database (with facts and predicates describing a given problem), and question(s) asked by users.Both the input facts and the questions can change dynamically, which leads to new model generation/formation.The main contribution of this study is the concept and implementation of the hybrid programming framework, which joins the ideas of (i) hybridization in the form of integration of MP and CLP, (ii) presolving in the form of transformation and constraint propagation, and (iii) autonomous search in the form of automatic generation of dedicated models to solve.Additionally, formal models of the scheduling problems for the illustrative examples before and after transformation are included.

The Concept of Hybrid Programming Framework Using Idea of an Autonomous Search
Based on the experience of hybridization and integration of CP/CLP/MP [5-8, 11, 13], the hybrid programing framework to modeling and solving CSPs and COPs has been proposed.The main assumptions used in the concept and implementation of the hybrid programming framework were as follows: (i) Integration of CLP and MP environments.
(ii) Introducing the framework presolving methods in the form of transformation and constraint propagation.
(iii) Knowledge base, which contains predicates for constraints, questions, methods, tools, and so forth and facts for data instances.
(iv) Implementation autonomous search in the form of automatic models generation for CSPs and COPs as the MP/MIP/MILP models based on knowledge base (constraints, questions, and data facts).
(v) The ability to solve MIP/MILP/MP models by internal and external solvers (LINGO [14] or SCIP [15] in this version of framework).
(vii) Implementation of the framework using the CLP environment (ECL i PS e system [16]).

Architecture of Hybrid Programming Framework.
Figure 2 shows a context scheme of the framework.The framework communicates with the knowledge database, the user, and the external MP solver(s).The knowledge database, which de facto is a part of the framework, consists of a set of various types of predicates, including those most simple facts.
The data instances of a given problem are saved as facts.
Relationships between individual facts define the information structure of the problem.Predicates and facts may concern different problems modeled and solved using the framework and for this reason they are identified through the problem index (id pro).The set of facts can be logically divided into two subsets: the subset of constant facts describing the problem and the subset changing the input facts.A user communicates with the framework by sending an inquiry/question in a suitable format and structure: Question (type, parameters, ID pro) .
The question determines what problem will be solved, with what parameters (i.e., which facts will be used), and defines the type of the question (which evaluation criterion will be used).An appropriate dedicated model will be generated depending on the formalization of this question, in particular, on its type.
Predicates can be logically divided into several groups.Particular groups of predicates (except for facts) that create the knowledge base are shown in Description of the Group Predicates.
A simplified functional scheme of the framework is shown in Figure 3; Algorithm 1 depicts the underlying/basic scenario of the framework operation, in the form of a pseudocode.
The user's question initiates the framework operation.The structure of the question in (1) defines the type of the question (general, wh-question, logical, etc.) and type of the problem and its detailed parameters (time, number of resources, size, etc.).Depending on the question, adequate information is extracted about the problem, data instances, problem size, and so forth.
Based on this information, the framework downloads suitable facts and predicates from the knowledge database.The facts are converted into lists.The reference model is built in CLP for a CSP or COP (variables and constraints).The model can be supplemented with additional constraints, including logic constraints if necessary.In the next step, the model is subjected to presolving.Two presolving methods are used in the framework, usually alternately: constraint propagation and transformation.After presolving, the model is the basis for generating the final implementation model in the form of an MP model (usually MILP).The MP model is then solved using an MP solver.

Transformation.
Transformation has been studied by the authors [11,13].It consists in changing the specification of a problem to eliminate unacceptable/nonfeasible points from the solution space prior to solving the problem.As a result, the number of decision variables is reduced and aggregated and the constraints are simplified and also the numbers of constraints is reduced, which leads to a smaller search space and, hence, shorter search time and the possibility to solve problems of larger size within allowable time limits.
Facts and problem constraints are used in the process of transformation.Transformation and constraint propagation are presolving methods applied in the framework.
In real practical problems, the transformation may involve the removal of unacceptable transportation routes in SCM problems [13] and the change of the problem specification from operational to resource type in task group scheduling [17], and so forth.

Illustrative Example and Computational Experiments
Practical use of framework for modeling and solving problems will be presented for illustrative example.As an illustrative example was selected job-shop scheduling problem with additional resources [18,19].Problems of this type can be found in manufacturing, logistics, computer networks, software engineering, and so forth.Formally, the illustrative example is an extension variant of job-shop scheduling problem and can be defined as follows.A set of  jobs/orders/products  = { 1 ,  2 , . . .,   } are given which require, for their processing, a set of  machines  = { 1 ,  2 , . . .,   } and a set of  additional resources  = { 1 ,  2 , . . .,   }.Each additional resource   has a specified limit ko  (number of units of the resource   ).Each job/order   is a sequence of  operations.The th operation of job/order   has to be executed by a specific machine   ∈  for time units (tr , is integer).Generally, in job-shop problems, a feasible schedule is such that (a) at any time each machine can execute at most one operation, (b) the operations of the same job/order are totally ordered, and (c) no preemption is allowed.Moreover, in our example, any time, each operation can be assisted by additional resources   where  ,, determines how much additional resources   are used to execute job/order   on machine   ∈ .Additional resources can be operators, tools, memory, transportation units, and so forth while basic resources are the machines/processors/workstations.A formal model of a scheduling problem for illustrative example, containing constraints, decision variables, and parameters, is shown in Appendix D.1.The collection of facts together with their structure for this model is included in Figure 4 (as the lowest layer of the information structure).
Both the proposed model and the structure of facts constitute a significant extension of the classical job-shop scheduling problem (JSSP) [18,19].Firstly, they allow accounting for additional resources , as described above.Secondly, the structure of constraints of the model, decision variables, and facts is universal and can describe not only jobshop scheduling problems but also those in other environments including flow-shop, open-shop, project, multiproject, and so forth.
Modeling starts with loading the set of facts for illustrative example to the knowledge base.Then, the facts are converted into lists using a general predicate (P1).In the next step, the set of predicates (P2) is created.This set implements the basic and additional/logic constraints for illustrative example.Then, the built or expanded set of predicates (P3) implements various types of questions (e.g., as in the exemplified questions asked to the illustrative example) for illustrative example.In the next step, predicates to transform modeled problem (P4) are taken from the knowledge base.Transformation for illustrative example involves the aggregation of the relevant facts (indexes of these facts) and building a list of only the feasible combinations of facts.The principle of the transformation of the facts for illustrative example is shown in Figure 5.
Exemplified questions asked to the illustrative example are as follows (Q1) What is the min  max (makespan)?The resulting list L index for facts from Appendix B.1 are presented in the Appendix B.2. Indices (the dimensions of the problem), decision variables, and constraints of the model are also subject to transformation.The transformation of indices (2a) stems from the fact that not every product  has to be manufactured on every machine .Thus, if product  is made on a specific machine , the existing values of index pair  The final step is the generation of a dedicated MILP model (files in the appropriate solver format or Mathematical Programming System (MPS)) using universal set of predicates for automatic generation (P5).Schematic structure of information for illustrative example in the form of facts, lists, and files is shown in Figure 4 and the description is shown in Table 3.The scenario of computational experiments was as follows.For any questions from the exemplified questions asked to the illustrative example and a given set of data instances (Appendix B.1), the generation of dedicated MILP models have been made using a hybrid programming framework.After that, the automatically generated models were solved using the external MP solvers like "LINGO" [14] or "SCIP" [15].Choosing solver "SCIP" was due to its high efficiency and the use of the built-in powerful presolving methods [15].As for the efficiency and effectiveness in the area of MP and CP, SCIP is the best option of all noncommercial solvers [15].CPLEX and Gurobi are certainly faster in solving the same benchmarks, but being commercial solvers, they mean higher costs (licenses, etc.).
Obtained results are shown in Table 1.The scope of the exemplified questions asked to the illustrative example shows the flexibility and capabilities of a hybrid programming framework.These are general questions (Q4, Q5, and Q6) and specified questions (Q1, Q2 A , Q2 B , and Q3), which require both optimal and feasible solutions.In addition, questions can be logical (Q7, Q8), whose modeling directly in an MP environment is not obvious and simple.To determine the effectiveness of the proposed framework for questions Q1, Q2 A , and Q2 B (for the most demanding computing), models were generated using the framework (Table 1) and modeled using only the classical mathematical programming (Table 2).Then, both groups of models were solved using LINGO and SCIP solvers.The answers to these questions using the framework are obtained 10 to 20 times faster than using just the pure MP solvers.In each case, the use of "SCIP" solver accelerated calculations twofold in comparison with the "LINGO" solver, with the "LINGO" solver (see columns  1 and  2 of Tables 1 and 2).
The models generated using the framework, respectively, have 20 times smaller number of decision variables and 3 times smaller number of constraints in relation to the models created only in MP environments.
The model file for Q1 questions in a format compatible with the "LINGO" is shown in Appendix C.
The file was generated by group predicates P5 on the basis of the information structure (Figure 5).

Conclusions
The proposed hybrid framework can be used in two modes.Firstly, it can be a platform for the end user to solve the COP and the CSP, which are generated and solved on the basis of existing knowledge base, but also the questions asked by the user.Secondly, it is a programming framework for modeling and solving the COP and the CSP.In this case, the user must know the environment CLP.For each new problem, users supplement the knowledge base of relevant predicates in P2 and P3 sets (see Description of the Group Predicates).
The concept of hybrid programming framework that combines (a) two programming paradigms (CLP/MP); (b) the presolving methods (transformation and constraint propagation); (c) autonomous search; and (d) the automatic generation of dedicated implementation models is the flexible and efficiency solution.Flexibility and easiness of modeling problems are caused by CLP-based approach which by nature is declarative.Efficiency is the result of applying the presolving methods, dedicated implementation models, and mathematical programming for solving.The idea of autonomous  search is implemented mainly through the mechanism of automatic generation of implementation models based on current data instances and the requirements of users (in the form of frequently asked questions) which means that models are better suited to current requirements and conditions and their solution requires less space search.The knowledge base of the framework, which is built from predicates and facts, provides scalability because knowledge base can be updated with new facts relating to existing models, predicates, and facts of new models and the facts resulting in answers to user questions and so on.
Further research will focus on two directions/areas.The first is to use a framework for modeling and solving other problems in the area of widely understood computer science.The second is the integration framework with other paradigms such as fuzzy logic and concurrent programming.
A new remotely accessible (e.g., in the cloud [20]) version of the framework is going to be developed.For licensing reasons, LINGO solver will be replaced by SCIP in this version.

A. Summary Facts, Lists, and Parameters for Illustrative Example
See Table 3.

C. MILP Model Automatically Generated by Framework (Set of Predicates P5) in LINGO Format
See Algorithm 4.

Decision Variables
,,, : if the additional resource  in period  is used to make the product  on the machine , then  ,,, = 1; otherwise,  ,,, = 0, Kp , : the number of last periods in which the product  is made on the machine ,  ,,, : if the period  is the latest in which the additional resource  is used to make the product  on the machine , then  ,,, = 1; otherwise,  ,,, = 0,  max : Makespan.
The allocation of resources  to the machine during product realization.
The allocation of at most one product to the machine in a given period of time.Operations cannot be interrupted.

Parameters
tr  : the time required to make implementation , ko  : the number of additional resources ,  , : if the additional resource  is used to make implementation , then  , determines the number of additional resources  necessary for this implementation; otherwise,  , = 0, 1 , : if the additional resource  is used to make implementation , then 1 , = 1; otherwise, 1 , = 0,  1,2 : if the implementation 1 to be executed before the implementation 2, then  1,2 = 1; otherwise,  1,2 = 0, wyk , : if the implementation  is made using a machine , then wyk , = 1; otherwise, wyk , = 0.

Inputs
or  : demand/order for implementation .

Auxiliary Parameters
op  : coefficients for conversion numbers of periods  for the variables op  = .

Decision Variables
,, : if the additional resource  in period  is used in implementation , then  ,, = 1; otherwise,  ,, = 0, Kp  : the number of last periods in which the implementation  is made,  ,, : if the period  is the latest in which the additional resource  is used in implementation , then  ,, = 1; otherwise,  ,, = 0,  max : Makespan.
Determination of the makespan.
The allocation of resources  to the machine during product realization.
The allocation of at most one product to the machine in a given period of time.The sequence of operations (precedence constraints).
Binary values and integer values.

Figure 1 :
Figure 1: The general scheme of the algorithm to solve CSP.

Figure 2 :
Figure 2: The concept of hybrid programming framework and its environment.

Figure 3 :
Figure 3: The functional diagram of hybrid programming framework.

FilesFigure 4 :Figure 5 :
Figure 4: The information structure for illustrative example implemented in hybrid programming framework.

(
, ) are replaced with the values of aggregated/transformed index .In the next step, the decision variables are subjected to transformation as a result of the aggregation of some of their indexes (2b).The set of all decision variables of the model before and after transformation are presented in Appendices D.1 and D.2, respectively.In the final stage, the constraints of the model transformed through the change (reduction) of summations and "for" phrase for the individual constraints.The constraints for model before and after the transformation are included in Appendices D.1 and D.2, respectively: (, ) → () (2a)  ,,, →  ,, | Kp , → Kp  |  ,,, →  ,, .(2b) pro, #id wer, #) #id pro: problem ID #id wer: version of the data instances #: product ID F machine (#id pro, #id wer, #) #id pro: problem ID #id wer: version of the data instances #: machine ID F technology (#id pro, #id wer, #, #, parameters) #id pro: problem ID #id wer: version of the data instances #: product ID #: machine ID tr , : the execution time of the product  on the machine  F precedence (#id pro, #id we, #, #, #) #id pro: problem ID #id wer: version of the data instances #: product ID #: machine ID F resources (#id pro, #id we, #, parameters) #id pro: problem ID #id wer: version of the data instances #: additional resource ID ko  : the total number of additional resources  F allocation (#id pro, #id we, #, #, #, parameters) #id pro: problem ID #id wer: version of the data instances #: additional resource ID #: machine ID #: product ID  ,, : the number of additional resources  needed to execute a product  on the machine  F model (#id pro, #id wer, #, parameters) #id pro: problem ID #id wer: version of the data instances #: model ID line  : line of code for model ID F order (#id pro, #id we, #, parameters) #id pro: problem ID #id wer: version of the data instances #: product ID or  : the size of the order for product  Lists L precedence (#, #, #) #: machine ID #: product ID L technology (#, #, parameters) #: product ID #: machine ID tr , : the execution time of the product  on the machine ;  , : if the product  is executed on the machine ,  , = 1; otherwise,  , = 0; or  : the size of the order for product  L allocation (#, #, #, parameters) #: additional resource ID #: machine ID #: product ID  ,, : the number of additional resources  needed to execute a product  on the machine ; ko  : the total number of additional resources  L model (#, parameters) #: model ID line  : line of code for model ID L index  (#, #, parameters) #: product ID #: machine ID : the new index after transformation L data  (#, parameters) #: the new index after transformation (combination of # and #) tr  : the execution time of the product  on the machine ;   : if the product  is executed on the machine,   = 1; otherwise,   = 0; or  : the size of the order for product  L precedence  (#, #) #: the new index after transformation (combination of # and #)
For the illustration example (Section 4), the transformation relies on the change problem representation through the appropriate aggregation of indices.For allowable values of indices of machines and products, an aggregated implementation index is created, the values of which are determined based on feasible values of base indices ((2a), (2b)).Details of the transformation in terms of indices, decision variables, constraints, and facts for the illustration example are presented in Section 4 and Appendices D.1 and D.2.3.3.Autonomous Search.Autonomous search, as used in the framework, is the narrowing of the search space through the implementation of presolving methods and automatic generation of dedicated implementation models.Both the presolving methods (constraint propagation and transformation) and model generation are based on current data instances.Users' questions are also taken into account while constructing the model.The questions may be related only to some of the aspects and constraints of the problem.Based on the current data, instances and users' questions ensure that the automatically generated models are dedicated and fit the specific situation.Such dedicated models have fewer decision variables and constraints.This shortens the search time (the search space is considerably reduced relative to that in universal models).A change of the question and/or data instance results in a new model adjusted to new parameters.
is the min  max if the set of additional resources is ko 1 = ko 2 = ko 3 = ko 4 = 2? Is it possible to schedule orders in   max and what are the sets of resources  1 ,  2 ,  3 ,  4 ?(Q5) Is it possible to schedule orders in   max if resources  1 and  4 cannot be used simultaneously?(Q6) Is it possible to schedule orders in   max if machines  7 and  9 cannot be used simultaneously?(Q7) What is the min  max if resources  1 and  4 cannot be used simultaneously?(Q8 A ) What is the min  max if machines  1 and  2 cannot be used simultaneously?(Q8 B ) What is the min  max if machines  7 and  9 cannot be used simultaneously?
(Q2 B ) What is the min  max if the set of additional resources is ko 1 = ko 2 = ko 3 = ko 4 = 3?(Q3) What is the minimum set of resources  1 at   max ?(Q4)

Table 1 :
Results for asked questions to the illustrative example (framework implementation).

Table 2 :
Results for asked questions to the illustrative example (MP implementation).: the number of decision variables.: the number of constraints. 1 : time of finding solution (in seconds) in LINGO. 2 : time of finding solution (in seconds) in SCIP.

Table 3 :
Description of the facts, lists, and parameters for the illustrative example.
Parameterstr , : the time required to make a product  on the machine ,  , : if the product  is made using a machine , then  , = 1; otherwise,  , = 0, ko  : the number of additional resource types ,  ,, : if the additional resource  is used to make the product  on the machine , then  ,, determines the number of additional resources  necessary for this execution; otherwise,  ,, = 0, 1 ,, : if the additional resource  is used to make the product  on the machine , then 1 ,, = 1; otherwise, 1 ,, = 0,  ,1,2 : if the operation of the product  on the machine 1 to be executed before the operation on the machine 2, then  ,1,2 = 1; otherwise,  ,1,2 = 0.
: demand/order for product . : coefficient for conversion number of periods  for the variable op  = .