Virtual Savant for the Knapsack Problem: learning for automatic resource allocation

This article presents the application of Virtual Savant to solve resource allocation problems, a widelystudied area with several real-world applications. Virtual Savant is a novel soft computing method that uses machine learning techniques to compute solutions to a given optimization problem. Virtual Savant aims at learning how to solve a given problem from the solutions computed by a reference algorithm, and its design allows taking advantage of modern parallel computing infrastructures. The proposed approach is evaluated to solve the Knapsack Problem, which models different variant of resource allocation problems, considering a set of instances with varying size and difficulty. The experimental analysis is performed on an Intel Xeon Phi many-core server. Results indicate that Virtual Savant is able to compute accurate solutions while showing good scalability properties when increasing the number of computing resources used.


Introduction
Resource allocation refers to the assignment of a number of available resources or assets to different issues or items. Resource allocation is an important concept that models several situations and problems arising in economics, strategic planning, project management, scheduling, logistics, production, engineering, and many other related areas [1]. Many resource allocation problems are modeled by the general framework formulated by the Knapsack Problem (Knapsack Problem) [2]. Knapsack Problem is a combinatorial optimization problem that, given a set of items with associated weights and profits, proposes determining the number of each item to include in a collection (i.e., the knapsack) in order to maximize the total profit while ensuring that the total weight is less than or equal to a given limit (i.e., the knapsack capacity). Different allocation problems are modeled by considering the capacity of the knapsack as the available amount of a given resource and the items as activities to which the resource can be allocated. This article describes a generic paradigm that proposes applying a computational intelligence approach to find accurate solutions to resource allocation problems modeled by the 0/1 Knapsack Problem in short computation times. 0/1 Knapsack Problem is a binary version of the Knapsack Problem where each item is considered as an atomic unit, i.e., each item can be included in the knapsack as a unit or discarded (i.e., it cannot be split to fill the knapsack). This binary version of the Knapsack Problem allows modeling interesting resource allocation problems such as activities in project management, scheduling and location problems, feature selection, among others. The Virtual Savant paradigm is applied to solve the 0/1 Knapsack Problem, which models allocation problems. Virtual Savant is a novel method that uses machine learning techniques to learn how a reference algorithm solves a given problem [3]. Virtual Savant is inspired by the savant syndrome, a rare condition in which a human demonstrates mnemonic or computing abilities far superior to what would be considered normal. As an example, some patients with savant syndrome (savants) are able to enumerate and identify huge prime numbers without the underlying knowledge of what a prime number is, or accurately determine the day of the week of a given date extremely fast. Reported evidence suggests that patients with savant syndrome use pattern recognition in order to efficiently solve problems [4,5,6]. The Virtual Savant paradigm proposes applying a learning approach using computational intelligence to predict the results computed by a reference algorithm that solves a given problem [7,3]. Virtual Savant receives as input a set of problem instances and the results computed by the reference algorithm, which is used to train a machine learning classifier. Once the training phase is completed, Virtual Savant can be applied to solve new, unknown, and even larger problem instances. In this way, the Virtual Savant paradigm aims at learning the behavior of a given resolution algorithm in order to generate a completely different program that reproduces an analogous but unknown process to compute accurate results for the same problem. Furthermore, the resulting generated program is lightweight and can take advantage of modern massively parallel computing architectures to provide a fast and powerful problem solving schema. Following previous works [8,9], this article describes a deeper study on how to solve the 0/1 Knapsack Problem using Virtual Savant. The first evaluation of Virtual Savant in a parallel environment (Intel Xeon Phi 7250 server) to solve the 0/1 Knapsack Problem is presented. The accuracy of the proposed approach is studied as well as its parallel capabilities and performance on a many-core computing environment. Experimental results when solving 0/1 Knapsack Problem instances of varying size and difficulty suggest that the proposed approach is able to compute competitive solutions while showing good scalability properties when increasing the number of processing elements. The article is organized as follows. Section 2 presents the 0/1 Knapsack Problem formulation, introduces Virtual Savant and presents an overview of the related literature. Section 3 outlines the application of Virtual Savant to the 0/1 Knapsack Problem. Section 4 presents the experimental evaluation of the proposed approach and, finally, Section 5 presents the conclusions and main lines of future work.

Problem and method
This section introduces the 0/1 knapsack problem, describes the Virtual Savant paradigm, and presents a review of the related literature.

0/1 Knapsack Problem formulation
The 0/1 Knapsack Problem is a classic combinatorial optimization problem which is proven to be NP-hard [10]. The mathematical formulation is as follows. Given a set of items, each with a profit and a weight , the 0/1 Knapsack Problem consists in finding a subset of items that maximizes the total profit, without exceeding the weight capacity of the knapsack. Eq. 1 shows the problem formulation, where ∈ 0,1 indicates whether item is included or not in the knapsack.
Despite its straightforward formulation, the 0/1 Knapsack Problem has a large solution space and is frequently used as a benchmark to evaluate optimization algorithms. Additionally, the 0/1 Knapsack Problem can be used to model several optimization problems with direct real-world applications in many fields.
In the context of this work, the 0/1 Knapsack Problem is useful to evaluate the Virtual Savant paradigm for several reasons: i) it is a NP-hard optimization problem; ii) it allows studying the behavior of Virtual Savant in problems with binary variables and simple constraints; iii) a large dataset of problem instances is publicly available with varying size and difficulty.

Virtual Savant
Virtual Savant is a novel paradigm to automatically generate programs that solve optimization problems in a massively parallel fashion [11]. The paradigm is inspired by the savant syndrome, a rare condition in which a person with significant mental disabilities has certain abilities far in excess of what would be considered normal [5]. People with this condition (savants) usually excel at one specific skill such as art, memory, rapid calculation, or musical abilities. The methods used by savants to solve problems are not fully understood due to the difficulties in communicating with them, since the syndrome is usually associated with autism. The main hypothesis states that savants learn through pattern recognition [4]. This mechanism allows savants to solve a given problem without understanding the underlying principles (e.g., being able to enumerate prime numbers without understanding what a prime number is). In analogy to the savant syndrome, Virtual Savant consists in training a machine learning classifier to automatically learn how to solve an optimization problem from a set of observations, which are usually obtained from a reference algorithm that solves the same problem. Once the training phase is completed, Virtual Savant can emulate the reference algorithm to solve new, unknown, and even larger problem instances, without the need of any further training. The Virtual Savant paradigm consists of two phases: classification, where results for unknown problem instances are predicted, and improvement, where predicted results are further improved using specific search procedures.

Related work
The 0/1 Knapsack problem has been widely studied in the operations research field. Nemhauser and Ullman [12] presented an exact algorithm to solve the 0/1 Knapsack Problem based on dynamic programming. The proposed algorithm was devised to solve capital allocation problems with constrained budgets, in the field of economics. Later, an optimized implementation of the original Nemhauser-Ullman algorithm was proposed by Harman et al. [13]. This version was applied to solve instances of the Next Release Problem, an optimization problem from software engineering where the goal is to determine the features to include in a new release of a given software product [14]. The optimized implementation by Harman et al. is used in our work to train the proposed Virtual Savant for 0/1 Knapsack Problem. Few articles were found in the related literature applying machine learning techniques to solve optimization problems, in line with the Virtual Savant proposal. Vinyals et al. [15] introduced Pointer Networks (ptr-nets), a model based on recurrent neural networks. Similarly to the approach applied in Virtual Savant, ptr-nets are trained by observing solved instances of a given problem and the proposed scheme is also able to deal with variable size outputs. The proposed model was applied to solve three different discrete combinatorial optimization problems: finding planar convex hulls, computing Delaunay triangulations, and solving the planar Travelling Salesman Problem. Experimental results indicated that the trained models were able to address problem instances larger than those seen during training and find competitive results for the studied problems. More recently, Hu et al. [16] applied a similar approach to the one proposed by Vinyals et al. to the three-dimensional bin packing problem, a specific variant of an allocation problem. A deep reinforcement learning approach is used to decide the sequence to pack items in a bin, while the empty space and the spatial orientation in which the items are placed inside the bin are calculated by heuristic methods. The reported experimental results showed that the proposed approach outperformed a specific heuristic for the problem. Improvements of 5% on average over the baseline results were obtained for the problem instances studied. Our previous works were able to obtain promising results when applying Virtual Savant to a task scheduling problem [17,18,7,11]. The application of Virtual Savant to the 0/1 Knapsack Problem has been previously studied in [8,9]. This article extends those two previous works by evaluating the parallel capabilities of the Virtual Savant model in a many-core parallel infrastructure.

Virtual Savant for the 0/1 Knapsack Problem
This section describes the application of the Virtual Savant paradigm to the 0/1 Knapsack Problem. The Virtual Savant implementation for the 0/1 Knapsack Problem uses Support Vector Machines (SVMs) for the classification phase. SVMs are trained using Nemhauser-Ullmann as a reference algorithm, which computes exact solutions for the 0/1 Knapsack Problem [13]. Each item of the problem instance is considered individually during the training phase of Virtual Savant. Therefore, each feature vector holds the weight and profit of the item, along with the capacity of the knapsack. The classification label is 0/1, indicating whether the reference algorithm included (or not) the item in the knapsack. Thus, a single solution of the reference algorithm provides as many observations as the number of items in the instance. The LIBSVM framework with a Radial Basis Function kernel was used [19]. A specific fork of the LIBSVM package was designed to improve training times on many-core architectures [20]. Fig. 1 outlines the training scheme for Virtual Savant to solve the 0/1 Knapsack Problem. Once the learning process is completed, Virtual Savant uses (in parallel) multiple instances of the trained SVM to predict whether or not to include each item in the knapsack. These decisions are independent for each item, providing Virtual Savant with a high degree of parallelism. The output of the classification phase is a vector that holds, for each item, the probability of including it in the knapsack. Since the length of the training vectors is fixed (3 features + 1 label), there is no need to re-train the SVM to solve problem instances of different size (i.e., with varying number of items). This allows Virtual Savant to easily scale to problem instances of larger dimensions, without requiring any additional training process. The improvement phase takes as input the resulting vector of probabilities computed in the prediction phase. One candidate solution is generated per computing resource available, by randomly sampling according to the probabilities of including each item. Finally, a local search heuristic is applied over each generated solution. The local search operator considered in this work is very simple, just performing random modifications on the items to include or not. On each step of the local search, a randomly-chosen bit in the solution is flipped, the new solution is evaluated, and the local search continues from that solution if an improvement is made. Algorithm 1 describes the method to evaluate the score of a solution in the local search procedure, considering a solution with profit , weight , overweight , where is the knapsack capacity; 0; ∈ 0,1 . , , and are scaled using the minimum and maximum weight and profit values in the problem instance. The improvement phase, as well as the prediction phase, is massively parallel, Massobrio R., Dorronsoro Díaz B., Nesmachnow Cánovas S.E. Virtual Savant for the Knapsack Problem: learning for automatic resource allocation. Trudy ISP RAN/Proc. ISP RAS, vol. 31, issue 2, 2019. pp. [21][22][23][24][25][26][27][28][29][30][31][32] 26 since more local searches can be spawned as more computing resources are available.  Two corrections schemes are included in the improvement phase in order to ensure that the returned solution satisfies the knapsack capacity restriction: • Greedy correction by profit (CP): iteratively removes the item with lower benefit until the total weight is lower than, or equal to, the knapsack capacity.
• Greedy correction by weight (CW): iteratively searches for the items with weight higher than, or equal to, the overweight of the solution and removes the one with the lowest weight among them. If no item satisfies this condition, it removes the one with the highest weight. The corrections are applied to each tentative solution after the local search, to ensure that the returned solution satisfies the knapsack capacity constraint. After all local searches and corrections are completed, the overall best solution found is returned.

Experimental analysis
This section reports the experimental analysis of the proposed Virtual Savant for the 0/1 Knapsack Problem.

Problem instances
The evaluation was performed over benchmark problem instances with different size and correlation between weight and profit of items. The correlation is related to the difficulty to solve an instance [13]. The benchmark includes 50 datasets, each with instances of size 100 to 1500 items (stepsize: 100). For each problem size, correlation varies from 0.0 to 1.0 (stepsize: 0.05). The benchmark, including a total of 15.750 problem instances, is publicly available at ucase.uca.es/nrp.

SVM training
The training phase was performed using dataset 1, to evaluate three different feature configurations. Results show that the best accuracy results were achieved when using item weight, item profit, and knapsack capacity. Regarding the size of the training set, results show that training with 15% of dataset 1 allows achieving good accuracy metrics. Increasing the number of observations results in marginal accuracy improvements, while significantly increasing training times. The parameters for the SVM (C) and the RBF kernel (γ) were configured prior to the experimental evaluation. Cross-validation was performed over a set of 5.000 samples randomly selected from dataset 1. Results suggest that the best results are computed with C=8192 and γ=0.5. Average accuracy for all datasets increased from 89.35% to 90.48% after parameter configuration. For the improvement phase, the parameters of the score assignment function in the local search were configured to m=0.2 and k=2 and the stopping criterion was set to 1000 iterations.

Experimental results
After configuration, the trained SVM was used to evaluate the complete Virtual Savant model on datasets 2 to 5. These datasets are completely new for the algorithm, as they were not used during the training phase. The experimental evaluation focused on both the quality of the solutions and the performance and scalability when using a massively parallel computing infrastructure.

Hardware platform
A many-core computing infrastructure was used in the experimental analysis, in order to evaluate the capabilities of Virtual Savant to compute accurate results over a massively parallel platform. A typical many-core computing infrastructure consists of tens or thousands of simpler independent cores. The use of many-core processors has been increasing in the past years, with extensive applications in embedded systems and high-performance computing platforms [21]. Many-core architectures can be programmed using the standard CPU model without needing specific knowledge about the underlying parallel hardware. Even without including platformspecific features, many-core systems offer support for serial legacy code [22]. The evaluation of Virtual Savant for the 0/1 Knapsack Problem was performed on an Intel Xeon Phi 7250 processor with 68 cores and 64GB RAM.

Scalability
Virtual Savant approach is elastic and adapts to the underlying hardware platform: if more computing resources are available, Virtual Savant can use them on both the prediction and the improvement phase. In the prediction phase, the computational load of predicting whether each item is included or not in the knapsack is balanced among the computing resources available. In the 28 improvement phase, Virtual Savant takes advantage of available resources to execute more local searches on tentative solutions, thus increasing the probability of computing more accurate results. The scalability of Virtual Savant when using a varying number of computing elements was evaluated for the prediction and improvement phases. Fig. 3 reports the average execution time (in seconds) for all problem instances studied when varying the number of threads.

Fig. 3. Execution time varying the number of threads
Results show that Virtual Savant scales very well when increasing the number of threads up to the number of cores available. When more threads are spawned, the performance starts degrading due to threads sharing resources. Consequently, the remainder of the experimental evaluation was performed using 68 threads. These results confirm the good scalability properties of Virtual Savant.

Virtual Savant: prediction phase accuracy
Boxplots in Figs. 4 and 5 correspond to the accuracy achieved during the prediction phase of Virtual Savant grouping problem instances by size and weight/profit correlation, respectively. The median prediction accuracy of the SVM is larger than 90% for all problem sizes studied. No significant differences are noticed among instances of different sizes. On the other hand, significant differences can be observed in the accuracy of the prediction phase on instances with varying weight/profit correlation. Instances with weight/profit correlation of 0.5 are the simplest to predict for the SVM, with a median accuracy value of over 97%. Additionally, in the worst case, the median accuracy of the SVM is larger than 80%.

Virtual Savant: quality of solutions
Results computed by Virtual Savant were compared with the known optima for the studied instances, to evaluate the efficacy of the proposed approach. Table 1 reports the average ratio to the optima for problem instances grouped by size. Table 2 reports the average ratio to the optimum, grouping instances by the correlation between weight and profit of items. Results achieved by Virtual Savant grouped by instance size differ from the known optima in just 2-4% on average for all problem instances studied. This is an encouraging result considering that the improvement phase of Virtual Savant consists in a straight-forward local search which does not incorporate any specific knowledge of the problem, thus making it potentially extensible to other related optimization problems. When looking at results grouped by weight/profit correlation, Virtual Savant allows computing accurate results for all problem instances studied. In the worst case, Virtual Savant differs from the optimum in 6% on average (for instances with no correlation between weight and profit).