Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
JP6190773B2 - Problem solving apparatus, method, and program - Google Patents
[go: Go Back, main page]

JP6190773B2 - Problem solving apparatus, method, and program - Google Patents

Problem solving apparatus, method, and program Download PDF

Info

Publication number
JP6190773B2
JP6190773B2 JP2014146547A JP2014146547A JP6190773B2 JP 6190773 B2 JP6190773 B2 JP 6190773B2 JP 2014146547 A JP2014146547 A JP 2014146547A JP 2014146547 A JP2014146547 A JP 2014146547A JP 6190773 B2 JP6190773 B2 JP 6190773B2
Authority
JP
Japan
Prior art keywords
node
rooted
subtree
sum
nodes
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
JP2014146547A
Other languages
Japanese (ja)
Other versions
JP2016024522A (en
Inventor
正彬 西野
正彬 西野
平尾 努
努 平尾
永田 昌明
昌明 永田
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NTT Inc
NTT Inc USA
Original Assignee
Nippon Telegraph and Telephone Corp
NTT Inc USA
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nippon Telegraph and Telephone Corp, NTT Inc USA filed Critical Nippon Telegraph and Telephone Corp
Priority to JP2014146547A priority Critical patent/JP6190773B2/en
Publication of JP2016024522A publication Critical patent/JP2016024522A/en
Application granted granted Critical
Publication of JP6190773B2 publication Critical patent/JP6190773B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Description

本発明は、問題解決装置、方法、及びプログラムに係り、特に、木制約付きナップサック問題を解決する問題解決装置、方法、及びプログラムに関する。   The present invention relates to a problem solving apparatus, method, and program, and more particularly, to a problem solving apparatus, method, and program for solving a tree-constrained knapsack problem.

従来より、容量Cのナップサック、及び個々のノードがアイテムに対応するノード数Nの木が与えられ、アイテムの容量、価値がそれぞれc,pである時、ナップサックの容量Cを超えない範囲で価値を最大化する根付き部分木を選択する問題が知られている。この問題は木制約付きナップサック問題(Tree Knapsack Problem)と呼ばれ、LATN(Local Access Telecommunication Network)、文書要約、文圧縮などの応用技術に利用される。 Conventionally, when a knapsack with capacity C and a tree with N nodes corresponding to items are provided for each node, and the capacity and value of the items are c i and p i , respectively, a range not exceeding the capacity C of the knapsack There is a known problem of selecting a rooted subtree that maximizes value. This problem is called a tree-constrained knapsack problem, and is used in application technologies such as LATN (Local Access Telecommunication Network), document summarization, and sentence compression.

木制約付きナップサック問題は以下の整数計画問題として定式化される。   The tree-constrained knapsack problem is formulated as the following integer programming problem.

=1の場合、i番目のアイテムが根付き部分木のノードとして選択されることを示す。(1)式は、価値を最大化するための目的関数であり、(2)式、及び(3)式が制約である。(2)式は選択された根付き部分木に含まれるアイテムの容量の和がナップサックの容量Cを超えないことを保証する。(3)式は選択されたアイテムが根付き部分木であることを保証する。なお、parent(i)とはi番目のノードの親のアイテムIDである。最適解は、分枝限定法(汎用ILPソルバを利用)、動的計画法を用いて得ることができる(非特許文献1、2)。 When x i = 1, it indicates that the i-th item is selected as a node of the rooted subtree. Equation (1) is an objective function for maximizing value, and Equations (2) and (3) are constraints. Equation (2) ensures that the sum of the capacities of the items included in the selected rooted subtree does not exceed the knapsack capacity C. Equation (3) ensures that the selected item is a rooted subtree. Parent (i) is the item ID of the parent of the i-th node. The optimal solution can be obtained using a branch and bound method (using a general-purpose ILP solver) or dynamic programming (Non-Patent Documents 1 and 2).

Lukes, J. A.“Efficient algorithm for the partitioning of trees.” IBM Journal of Research and Development, 18(3), 217-224.(1974)Lukes, J. A. “Efficient algorithm for the partitioning of trees.” IBM Journal of Research and Development, 18 (3), 217-224. (1974) Morita, H., Sasano, R., Takamura, H. and Okumura, M. “Subtree Extractive Summarization via SubmodularMaximization.” Proceedings of the 51st Annual Meeting of the Association for Computational Linguistics, 1023-1032.(2013)Morita, H., Sasano, R., Takamura, H. and Okumura, M. “Subtree Extractive Summarization via SubmodularMaximization.” Proceedings of the 51st Annual Meeting of the Association for Computational Linguistics, 1023-1032. (2013)

非特許文献1、2に記載の分枝限定法は探索木を枝狩りしつつ解を列挙する手法であるため、ナップサックの容量C、木のノード数(アイテム数)Nによっては効率的に解を得ることができない。さらに、用いるILPソルバプログラムによって処理速度が大きく異なるという問題がある。また、これまでに提案された動的計画法は計算量がO(NC) であるため、Cの値によっては計算効率が悪いという問題もある。 Since the branch and bound method described in Non-Patent Documents 1 and 2 is a method of enumerating solutions while branch-hunting the search tree, the solution can be efficiently solved depending on the capacity C of the knapsack and the number of nodes (number of items) N of the tree. Can't get. Furthermore, there is a problem that the processing speed varies greatly depending on the ILP solver program to be used. In addition, since the dynamic programming methods proposed so far have a calculation amount of O (NC 2 ), there is a problem that calculation efficiency is poor depending on the value of C.

本発明は、上記問題点を解決するために成されたものであり、木制約付きナップサック問題を高速に解くことができる問題解決装置、方法、及びプログラムを提供することを目的とする。   The present invention has been made to solve the above problems, and an object of the present invention is to provide a problem solving apparatus, method, and program capable of solving a tree-constrained knapsack problem at high speed.

上記目的を達成するために、第1の発明に係る問題解決装置は、価値と容量を持つノードの各々から構成される木構造から、容量制限C以下で価値を最大化する根付き部分木を選択する木制約付きナップサック問題を解決する問題解決装置であって、前記木構造を構成する各ノードを、前記木構造の根からの深さ優先の順序で並べ替えるソート部と、前記ソート部により並べ替えられた各ノードの順序に従って、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の前記根付き部分木について、各ノードの価値の和の最大値を計算して記憶部に記憶する最適値計算部と、を含んで構成されており、前記最適値計算部によって繰り返し計算された計算過程に基づいて、前記容量制限C以下となる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を出力するバックトラック部とを含み、前記最適値計算部は、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を計算するとき、各成長段階の前記根付き部分木について前記記憶部に記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる前記n−1番目のノードを含まない根付き部分木とのうち、前記部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算する。   In order to achieve the above object, the problem solving apparatus according to the first invention selects a rooted subtree that maximizes the value below the capacity limit C, from a tree structure composed of nodes each having value and capacity. A problem solving apparatus that solves a tree-constrained knapsack problem, wherein the nodes constituting the tree structure are rearranged in a depth-first order from the root of the tree structure, and the sorting unit arranges the nodes According to the order of each replaced node, the n-th node is a rooted subtree in which the n-th node can be added to each capacity c (0 ≦ c ≦ C), and the sum of the capacities of the nodes Among the rooted subtrees having the same value as the capacity c, by repeatedly calculating the rooted subtree having the maximum value of the nodes of the rooted subtree, the sum of the values of the nodes of the rooted subtree is maximized. And an optimum value calculation unit that calculates the maximum value of the sum of the values of each node and stores them in the storage unit for the rooted subtree at each growth stage. A rooted portion where the sum of the values of the nodes of the rooted subtree is maximized among the rooted subtrees that are less than or equal to the capacity limit C based on the calculation process repeatedly calculated by the optimum value calculation unit. A backtrack unit that outputs a tree, wherein the optimum value calculation unit is a rooted subtree to which an nth node can be added, and the sum of the capacities of the nodes is equal to the capacity c Among them, when calculating a rooted subtree that maximizes the sum of the values of each node of the rooted subtree, the maximum value of the sum of the values of each node stored in the storage unit for the rooted subtree of each growth stage The A rooted subtree to which an nth node can be added, and a rooted subtree including an (n-1) th node in which the sum of the capacities of each node is equal to the capacity c, and an nth node Among the rooted subtrees that can be added and that do not include the (n-1) th node whose sum of capacities of the nodes is equal to the capacity c, the sum of the values of the nodes of the subtree Recursively computes the rooted subtree for which

また、第1の発明に係る問題解決装置において、前記最適値計算部は、以下の(5)式を用いて、前記記憶部に記憶された、前記n番目のノード及び前記容量cの組み合わせの各々に対する、各ノードの価値の和の最大値S[n][c]を格納する配列を初期化し、前記n番目のノード及び前記容量cの組み合わせの各々について、以下の(6)式を用いて、前記組み合わせに対する、各ノードの価値の和の最大値S[n][c]を計算して、前記記憶部に記憶された前記配列に格納してもよい。   Further, in the problem solving apparatus according to the first invention, the optimum value calculation unit uses the following equation (5) to calculate the combination of the nth node and the capacity c stored in the storage unit: An array for storing the maximum sum S [n] [c] of the value of each node for each is initialized, and the following expression (6) is used for each combination of the nth node and the capacity c. Then, the maximum sum S [n] [c] of the values of the nodes for the combination may be calculated and stored in the array stored in the storage unit.

ただし、A[n]は、n番目のノードを表し、関数cap(A[n])は、n番目のノードの容量を表し、p(A[n])は、n番目のノードの価値を表し、関数next_undesc(h)は、h+1番目以降のノードのうち、h番目のノードの子孫でない最初のノードのインデックスを返す関数を表す。   However, A [n] represents the nth node, the function cap (A [n]) represents the capacity of the nth node, and p (A [n]) represents the value of the nth node. The function next_undesc (h) represents a function that returns the index of the first node that is not a descendant of the h-th node among the h + 1 and subsequent nodes.

第1の発明に係る問題解決方法は、価値と容量を持つノードの各々から構成される木構造から、容量制限C以下で価値を最大化する根付き部分木を選択する木制約付きナップサック問題を解決する問題解決装置における問題解決方法であって、ソート部が、前記木構造を構成する各ノードを、前記木構造の根からの深さ優先の順序で並べ替えるステップと、最適値計算部が、前記ソート部により並べ替えられた各ノードの順序に従って、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の前記根付き部分木について、各ノードの価値の和の最大値を計算して記憶部に記憶するステップと、バックトラック部が、前記最適値計算部によって繰り返し計算された計算過程に基づいて、前記容量制限C以下となる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を出力するステップとを含んで実行することを特徴としており、前記最適値計算部によって計算するステップは、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を計算するとき、各成長段階の前記根付き部分木について前記記憶部に記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる前記n−1番目のノードを含まない根付き部分木とのうち、前記部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算する。   The problem-solving method according to the first invention solves the tree-constrained knapsack problem of selecting a rooted subtree that maximizes the value below the capacity limit C from a tree structure composed of nodes having value and capacity. A problem solving method in the problem solving apparatus, wherein the sorting unit rearranges each node constituting the tree structure in a depth-first order from the root of the tree structure, and an optimum value calculation unit includes: In accordance with the order of the nodes rearranged by the sorting unit, for the nth node, a rooted subtree that can add the nth node to each capacity c (0 ≦ c ≦ C), and Among the rooted subtrees in which the sum of the capacities of the nodes is equal to the capacity c, the rooted subtree having the maximum sum of the values of the nodes of the rooted subtree is repeatedly calculated, thereby obtaining the rooted subtree. Gradually growing a rooted subtree with the largest sum of node values, calculating a maximum sum of values of each node for the rooted subtree in each growth stage, and storing it in a storage unit; Based on the calculation process in which the backtrack unit is repeatedly calculated by the optimum value calculation unit, among the rooted subtrees that are less than or equal to the capacity limit C, the rooting that maximizes the sum of the values of the nodes of the rooted subtree And outputting the subtree. The step of calculating by the optimum value calculation unit is a rooted subtree to which the nth node can be added, and the capacity of each node is calculated. Among the rooted subtrees whose sum is equal to the capacity c, when calculating the rooted subtree having the maximum value of each node of the rooted subtree, the rooted portion of each growth stage is calculated. N is a rooted subtree that can be added to the nth node by calling the maximum sum of the values of the nodes stored in the storage unit, and the sum of the capacities of the nodes is equal to the capacity c. A rooted subtree including the −1st node and a rooted subtree to which the nth node can be added, and does not include the n−1th node in which the sum of the capacities of the nodes is equal to the capacity c. Among the rooted subtrees, a rooted subtree that maximizes the sum of the values of the nodes of the subtree is recursively calculated.

また、第1の発明に係る問題解決方法において、前記最適値計算部によって計算するステップは、以下の(8)式を用いて、前記記憶部に記憶された、前記n番目のノード及び前記容量cの組み合わせの各々に対する、各ノードの価値の和の最大値S[n][c]を格納する配列を初期化し、前記n番目のノード及び前記容量cの組み合わせの各々について、以下の(9)式を用いて、前記組み合わせに対する、各ノードの価値の和の最大値S[n][c]を計算して、前記記憶部に記憶された前記配列に格納してもよい。   In the problem solving method according to the first aspect of the present invention, the step of calculating by the optimum value calculating unit uses the following equation (8) to store the nth node and the capacity stored in the storage unit: For each combination of c, an array storing the maximum sum S [n] [c] of the values of the nodes is initialized, and for each combination of the nth node and the capacity c, the following (9 ) May be used to calculate the maximum sum S [n] [c] of the values of the nodes for the combination and store it in the array stored in the storage unit.

ただし、A[n]は、n番目のノードを表し、関数cap(A[n])は、n番目のノードの容量を表し、p(A[n])は、n番目のノードの価値を表し、関数next_undesc(h)は、h+1番目以降のノードのうち、h番目のノードの子孫でない最初のノードのインデックスを返す関数を表す。   However, A [n] represents the nth node, the function cap (A [n]) represents the capacity of the nth node, and p (A [n]) represents the value of the nth node. The function next_undesc (h) represents a function that returns the index of the first node that is not a descendant of the h-th node among the h + 1 and subsequent nodes.

また、第1の本発明に係るプログラムは、コンピュータを、上記の第1の発明に係る問題解決装置を構成する各部として機能させるためのプログラムである。   A program according to the first aspect of the present invention is a program for causing a computer to function as each part constituting the problem solving apparatus according to the first aspect of the present invention.

本発明の問題解決装置、方法、及びプログラムによれば、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の根付き部分木について、各ノードの価値の和の最大値を計算して記憶部に記憶し、各成長段階の根付き部分木について記憶部に記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含まない根付き部分木とのうち、部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算することで、木制約付きナップサック問題を高速に解くことができる、という効果が得られる。   According to the problem solving apparatus, method, and program of the present invention, for the n-th node, a rooted subtree capable of adding the n-th node to each capacity c (0 ≦ c ≦ C), and Among the rooted subtrees in which the sum of the capacities of the nodes is equal to the capacity c, the value of each node of the rooted subtree is calculated by repeatedly calculating the rooted subtree having the maximum sum of the values of the nodes of the rooted subtree. The rooted subtree with the largest sum is gradually grown, and for the rooted subtree at each growth stage, the maximum sum of the values of each node is calculated and stored in the storage unit, and the rooted part at each growth stage N is a rooted subtree in which the nth node can be added by calling the maximum sum of the values of each node stored in the storage unit for the tree, and the sum of the capacities of the nodes is equal to the capacity c -1st node A rooted subtree including a rooted subtree to which an nth node can be added, and a rooted subtree not including the (n−1) th node in which the sum of the capacities of the nodes is equal to the capacity c, By recursively calculating the rooted subtree that maximizes the sum of the values of the nodes of the subtree, the effect of being able to solve the tree-constrained knapsack problem at high speed is obtained.

本発明の実施の形態に係る問題解決装置の構成を示すブロック図である。It is a block diagram which shows the structure of the problem solving apparatus which concerns on embodiment of this invention. 価値と容量を持つノードの各々から構成される木構造の概念図である。It is a conceptual diagram of the tree structure comprised from each of a node with value and capacity. 二次元配列S、Bに格納する各要素を決定するアルゴリズムを示す図である。It is a figure which shows the algorithm which determines each element stored in the two-dimensional array S and B. 二次元配列Sの各要素の例を示す概念図である。3 is a conceptual diagram illustrating an example of each element of a two-dimensional array S. FIG. 二次元配列Bの各要素の例を示す概念図である。3 is a conceptual diagram illustrating an example of each element of a two-dimensional array B. FIG. バックトラックのアルゴリズムを示す図である。It is a figure which shows the algorithm of a backtrack. 本発明の実施の形態に係る問題解決装置における問題解決処理ルーチンを示すフローチャートである。It is a flowchart which shows the problem-solving process routine in the problem-solving apparatus which concerns on embodiment of this invention. 本発明の実施の形態に係る問題解決装置における最大価値計算処理ルーチンを示すフローチャートである。It is a flowchart which shows the maximum value calculation process routine in the problem-solving apparatus which concerns on embodiment of this invention. 本発明の実施の形態に係る問題解決装置における兄弟要素決定処理ルーチンを示すフローチャートである。It is a flowchart which shows the sibling element determination processing routine in the problem solving apparatus which concerns on embodiment of this invention. 本発明の実施の形態に係る問題解決装置におけるバックトラック処理ルーチンを示すフローチャートである。It is a flowchart which shows the backtrack process routine in the problem-solving apparatus which concerns on embodiment of this invention.

以下、図面を参照して本発明の実施の形態を詳細に説明する。   Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings.

<本発明の実施の形態に係る問題解決装置の構成> <Configuration of Problem Solving Device According to Embodiment of the Present Invention>

本発明の実施の形態に係る問題解決装置の構成について説明する。図1に示すように、本発明の実施の形態に係る問題解決装置100は、CPUと、RAMと、後述する問題解決処理ルーチンを実行するためのプログラムや各種データを記憶したROMと、を含むコンピュータで構成することが出来る。この問題解決装置100は、機能的には図1に示すように入力部10と、演算部20と、出力部50とを備えている。   The configuration of the problem solving apparatus according to the embodiment of the present invention will be described. As shown in FIG. 1, a problem solving apparatus 100 according to an embodiment of the present invention includes a CPU, a RAM, and a ROM that stores a program and various data for executing a problem solving processing routine described later. Can be configured with a computer. Functionally, the problem solving apparatus 100 includes an input unit 10, a calculation unit 20, and an output unit 50 as shown in FIG.

入力部10は、アイテムをノードとした、価値と容量を持つノードの各々から構成される木構造と、容量制限Cとを入力として受け付ける。   The input unit 10 receives, as inputs, a tree structure composed of nodes each having a value and a capacity, with the item as a node, and a capacity limit C.

演算部20は、ソート部30と、記憶部31と、最適値計算部32と、バックトラック部34とを含んで構成されている。   The computing unit 20 includes a sorting unit 30, a storage unit 31, an optimum value calculation unit 32, and a backtrack unit 34.

ソート部30は、入力部10で受け付けた木構造を構成する各ノードを、木構造の根からの深さ優先の順序で並べ替える。例えば、図2に示す木構造を構成する各ノードをソート部が受け取るとノードをプレオーダでソートし、ソートされた配列A=(v,v,v,v,v,v,v,v,v)を最適値計算部32へ渡す。また、図2の各ノードの左上に付された数値が、各ノードのインデックスを示す。 The sorting unit 30 rearranges the nodes constituting the tree structure received by the input unit 10 in the depth-first order from the root of the tree structure. For example, when the sorting unit receives each node constituting the tree structure shown in FIG. 2, the nodes are sorted in a pre-order, and the sorted array A = (v 9 , v 1 , v 2 , v 5 , v 3 , v 4 , V 6 , v 7 , v 8 ) are passed to the optimum value calculation unit 32. Also, the numerical value given to the upper left of each node in FIG. 2 indicates the index of each node.

記憶部31には、(N+1)×(C+1)の二次元配列であって、根付き部分木に含まれる各ノードの価値の和の最大値を各要素に格納する二次元配列S、並びに、根付き部分木を得るための情報として各ノードのインデックス及びタイプを各要素に格納する二次元配列Bが記憶されている。   The storage unit 31 is a (N + 1) × (C + 1) two-dimensional array, a two-dimensional array S for storing the maximum sum of values of nodes included in the rooted subtree in each element, and a rooted As information for obtaining a subtree, a two-dimensional array B that stores the index and type of each node in each element is stored.

最適値計算部32は、ソート部30により並べ替えられた各ノードの順序に従って、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の根付き部分木について、各ノードの価値の和の最大値を計算して記憶部31の配列Sに記憶する。また、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、根付き部分木の各ノードの価値の和が最大となる根付き部分木を計算するとき、各成長段階の根付き部分木について記憶部31の配列Sに記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含まない根付き部分木とのうち、部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算する。   The optimum value calculator 32 can add a n-th node to each capacity c (0 ≦ c ≦ C) for the n-th node according to the order of the nodes rearranged by the sort unit 30. In addition, among the rooted subtrees in which the sum of the capacities of the nodes is equal to the capacity c, the rooted subtree is repeatedly calculated by repeatedly calculating the rooted subtree having the maximum sum of the values of the nodes in the rooted subtree. The rooted subtree that maximizes the sum of the values of the nodes of the tree is gradually grown, and for the rooted subtree of each growth stage, the maximum sum of the values of the nodes is calculated and the array S of the storage unit 31 is calculated. To remember. Further, among the rooted subtrees in which the nth node can be added and the sum of the capacities of the nodes is equal to the capacity c, the sum of the values of the nodes of the rooted subtree is maximized. When calculating a rooted subtree, a rooted subtree that can add an nth node by calling the maximum sum of values of each node stored in the array S of the storage unit 31 for the rooted subtree of each growth stage. And a rooted subtree including the (n-1) th node in which the sum of the capacities of the nodes is equal to the capacity c, and a rooted subtree to which the nth node can be added, and the capacity of each node Among the rooted subtrees not including the (n−1) th node whose sum is equal to the capacity c, the rooted subtree having the maximum sum of the values of the nodes of the subtree is recursively calculated.

具体的には、最適値計算部32は、まず、以下の(11)式を用いて、記憶部31に記憶された、n番目のノード及び容量cの組み合わせの各々に対する、各ノードの価値の和の最大値S[n][c]を格納する配列Sを初期化する。ただし、1≦n≦N+1、0≦c≦Cである。なお、容量制限C及び容量cは共に整数である。二次元配列Sの要素S[n][c]には、配列Aのn番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量がcと等しくなるn−1番目のノードを含む根付き部分木と、当該n−1番目のノードを含まない根付き部分木とのうち、部分木の各ノードの価値の和が最大となる根付き部分木の最大値が格納される。   Specifically, the optimum value calculation unit 32 first calculates the value of each node for each combination of the nth node and the capacity c stored in the storage unit 31 using the following equation (11). An array S for storing the maximum sum S [n] [c] is initialized. However, 1 ≦ n ≦ N + 1 and 0 ≦ c ≦ C. Note that the capacity limit C and the capacity c are both integers. The element S [n] [c] of the two-dimensional array S is a rooted subtree to which the nth node of the array A can be added, and the n−1th node whose capacity is equal to c The maximum value of the rooted subtree where the sum of the values of the nodes of the subtree is maximized is stored.

次に、最適値計算部32は、以下の(12)式の再帰式を用いて、n番目のノード及び容量cの組み合わせの各々について、当該組み合わせに対する、各ノードの価値の和の最大値S[n][c]を計算して、記憶部31に記憶された配列に格納していく。(12)式では、上記S[n][c]に格納される根付き部分木の最大値について、(a)n−1番目のノードを含む根付き部分木、又は(b)n−1番目のノードを含まない根付き部分木の中から選択している。(12)式の1行目がn−1番目のノードを含む根付き部分木の各ノードの価値の和のスコアに、2、3行目がn−1番目のノードを含まない根付き部分木の各ノードの価値の和のスコアに対応している。   Next, the optimum value calculation unit 32 uses, for each combination of the nth node and the capacity c, the maximum value S of the sums of the values of the respective nodes with respect to the combination using the recursive equation of the following expression (12). [N] [c] is calculated and stored in the array stored in the storage unit 31. In the expression (12), with respect to the maximum value of the rooted subtree stored in S [n] [c], (a) the rooted subtree including the (n−1) th node, or (b) the (n−1) th subtree. A rooted subtree that does not contain nodes is selected. (12) The first line of the expression is the sum of the values of the nodes of the rooted subtree including the (n−1) th node, and the second and third lines are rooted subtrees that do not include the (n−1) th node. Corresponds to the score of the sum of the values of each node.

ここで、A[n]は、n番目のノードを表し、関数cap(A[n])は、n番目のノードの容量を表し、p(A[n])は、n番目のノードの価値を表している。   Here, A [n] represents the nth node, the function cap (A [n]) represents the capacity of the nth node, and p (A [n]) represents the value of the nth node. Represents.

また、関数prev(n)は関数next_undesc()の値がnとなる配列Aのインデックスを返す関数であり、以下(13)式で定義する。   The function prev (n) is a function that returns an index of the array A in which the value of the function next_undesc () is n, and is defined by the following equation (13).

関数next_undesc(h)は、h+1番目以降のノードのうち、h番目のノードの子孫でない最初のノードのインデックスを返す関数を表す。例えば、配列Aの部分配列A[h+1,...,N]からA[h]の子孫ではない最初のノードのインデックスを返す。仮に、部分配列A[h+1,...,N]にA[h]の子孫でないノードが存在しなかった場合は、next_undesc(h)=N+1とする。例えば、配列Aにおいて、h=2とすると、A[2]=vであるから、その子孫はv,v,v,vとなる。そこでA[3,...,9]からこれらの子孫を削除すると(v,v,v)が得られる。よって、next_undesc(2)は、vの配列Aにおけるインデックスである7を返す。同様にnext_undesc(4)、next_undesc(6)も7であることから、prev(7)の場合、h番目のノードは{2,4,6}となる。 The function next_undesc (h) represents a function that returns the index of the first node that is not a descendant of the h-th node among the h + 1 and subsequent nodes. For example, the partial array A [h + 1,. . . , N] returns the index of the first node that is not a descendant of A [h]. Suppose that the partial array A [h + 1,. . . , N], there is no node that is not a descendant of A [h], then next_undesc (h) = N + 1. For example, in array A, if h = 2, then A [2] = v 1 , so its descendants are v 2 , v 3 , v 4 , v 5 . Therefore, A [3,. . . , 9] to delete these offsprings yields (v 6 , v 7 , v 8 ). Therefore, next_undesc (2) returns 7 is an index in the array A v 6. Similarly, next_undesc (4) and next_undesc (6) are also 7, so in the case of prev (7), the h-th node is {2, 4, 6}.

ここで、根付き部分木に含まれる各ノードの価値の和の最大値を格納する二次元配列S、及び根付き部分木を得るための情報を格納する二次元配列Bに対する各要素を効率的に決定するためのアルゴリズムを、図3のAlgorithm1に示す。   Here, each element for the two-dimensional array S for storing the maximum sum of the values of the nodes included in the rooted subtree and the two-dimensional array B for storing information for obtaining the rooted subtree is efficiently determined. The algorithm for doing this is shown in Algorithm 1 in FIG.

Algorithm1では、まず、アルゴリズムの1行目で木構造を構成する各ノードをプレオーダでソートし、配列Aに格納する。そして、3から35行目で、(N+1)×(C+1)の二次元配列S、及びBの各要素を決定する。   In Algorithm 1, first, each node constituting the tree structure is sorted by pre-order in the first line of the algorithm, and stored in the array A. Then, in the 3rd to 35th lines, each element of the (N + 1) × (C + 1) two-dimensional array S and B is determined.

具体的には、二次元配列S、及びBの初期化を行う(図3の3から8行目)。そして、スタックsiblingsに値N+1を積み(9行目)、S[1][0]の要素を0とする(10行目)。   Specifically, the two-dimensional arrays S and B are initialized (lines 3 to 8 in FIG. 3). Then, the value N + 1 is stacked on the stack siblings (9th line), and the element of S [1] [0] is set to 0 (10th line).

次に、n(2≦n≦N+1)について、11行目からの繰り返し処理によって、0≦c≦Cに対し、二次元配列S、及びBの各要素の値を決定する。   Next, for n (2 ≦ n ≦ N + 1), the values of the elements of the two-dimensional arrays S and B are determined for 0 ≦ c ≦ C by iterative processing from the 11th row.

そして、c−cap(A[n−1])の容量がゼロ以上、かつS[n−1][c−cap(A[n−1])]の価値のスコアがゼロ以上の場合、S[n][c]よりもS[n][c−cap(A[n−1])]+p(A[n−1])が大きいならばS[n][c]にS[n−1][c−cap(A[n−1])]+p(A[n−1])の価値のスコアを代入する(13から18行目)。そして、B[n][c]にインデックスとタイプを表すタプル(n−1,DIAGONAL)を格納する。タイプがDIAGONALの場合、プレオーダインデックスが1からn−1番目までのノードを使って構成される、容量の和がcである、各ノードの価値の和を最大化する根付き部分木に、プレオーダインデックスn−1番目のノードが利用されたことを示す。   When the capacity of c-cap (A [n-1]) is zero or more and the score of the value of S [n-1] [c-cap (A [n-1])] is zero or more, S If S [n] [c-cap (A [n-1])] + p (A [n-1]) is larger than [n] [c], then S [n] [c] 1] Substitute the value score of [c-cap (A [n-1])] + p (A [n-1]) (13th to 18th lines). Then, a tuple (n−1, DIAGONAL) representing an index and a type is stored in B [n] [c]. When the type is DIAGONAL, a pre-order index composed of nodes 1 to n−1 and having a capacity sum of c and a rooted subtree that maximizes the sum of the values of the nodes Order index n-1 indicates that the first node is used.

次に、スタックsiblingsの一番上の値がn−1であるならば、それを取り除く(20から21行目)。そして、ノードA[n−1]の右側に存在する兄弟のうち最左の兄弟のプレオーダインデックスをkとする。ノードA[n−1]の右側に兄弟がいない場合は、スタックsiblingsの一番上に積まれたインデックスをkとし、そうでなければ、kをスタックsiblingsへ積む(23から28行目)。   Next, if the top value of the stack siblings is n-1, remove it (20th to 21st lines). Then, let k be the preorder index of the leftmost sibling among the siblings existing on the right side of the node A [n−1]. If there is no sibling on the right side of the node A [n−1], the index stacked at the top of the stack siblings is set to k. Otherwise, k is stacked on the stack siblings (23rd to 28th lines).

そして、0≦c≦Cに対し、S[k][c]、及びB[k][c]の各要素を決定する。S[n−1][c]がS[k][c]よりも大きければS[k][c]にS[n−1][c]の価値のスコアを格納し、B[k][c]にインデックスとタイプを表すタプル(n−1,UPRIGHT)を格納する(29から34行目)。タイプがUPRIGHTの場合、プレオーダインデックスが1からk−1番目までのノードを使って構成される、容量の和がcと等しくかつ各ノードの価値の和を最大化する根付き部分木に対し、プレオーダインデックスn−1番目のノードが利用されていないことを示す。   Then, for 0 ≦ c ≦ C, each element of S [k] [c] and B [k] [c] is determined. If S [n−1] [c] is larger than S [k] [c], the value score of S [n−1] [c] is stored in S [k] [c], and B [k] [C] stores a tuple (n-1, UPRIGHT) indicating an index and a type (lines 29 to 34). If the type is UPRIGHT, for a rooted subtree composed of nodes with preorder indices from 1 to k−1 and having a capacity sum equal to c and maximizing the sum of the values of each node, This indicates that the pre-order index n-1st node is not used.

上記図2に示す木構造を構成する各ノードに対して、ノードの容量c、及び価値pが表1のとおり与えられたとき、ナップサックの容量制限C=10とすると、二次元配列S対して、n番目のノード及び容量cの組み合わせの各々について、各ノードの価値の和の最大値を格納した場合、図4のようになる。また、二次元配列Bに対して、n番目のノード及び容量cの組み合わせの各々について、根付き部分木を得るための情報を格納すると図5のようになる。   When the node capacity c and the value p are given as shown in Table 1 for each node constituting the tree structure shown in FIG. 2, assuming that the knapsack capacity limit C = 10, the two-dimensional array S For each combination of the nth node and the capacity c, the maximum sum of the values of the nodes is stored as shown in FIG. Further, when information for obtaining a rooted subtree is stored for each combination of the nth node and the capacity c in the two-dimensional array B, the result is as shown in FIG.

バックトラック部34は、最適値計算部32によって繰り返し計算された計算過程に基づいて、容量制限C以下となる根付き部分木のうち、根付き部分木の各ノードの価値の和が最大となる根付き部分木を出力部50に出力する。   Based on the calculation process repeatedly calculated by the optimum value calculation unit 32, the backtrack unit 34 has a rooted portion in which the sum of the values of the nodes of the rooted subtree is maximized among the rooted subtrees having a capacity limit C or less. The tree is output to the output unit 50.

ここで、最適値計算部で生成した二次元配列S、及びBを用いて容量制限C以下でアイテムの価値の和を最大化する根付き部分木を得るバックトラックのアルゴリズムを図6のAlgorithm2に示す。   Here, Algorithm 2 of FIG. 6 shows a backtracking algorithm that obtains a rooted subtree that maximizes the sum of the values of items below the capacity limit C using the two-dimensional arrays S and B generated by the optimum value calculation unit. .

最適値計算部32による計算により、容量制限C以下で各ノードの価値の和を最大化する根付き部分木のスコアは、記憶部31に記憶された二次元配列SのN+1行目に格納されている。よって、まず容量制限C以下で価値の和を最大化する根付き部分木のスコアを格納するSのN+1行目における列を決定し、決定した列をmax_idxとする(3行目)。そして、二次元配列BのN+1の行、max_idxの列から順にバックトラックを行う(9から18行目)。nを行、mを列として、初期位置は、nがN+1の行、mがmax_idxの列から開始し、B[n][m]に格納されているタプルのタイプがDIAGONALであれば、当該インデックスkを配列treeへプッシュする。そして、nにkを代入し、mにm−cap(A[k])を代入する。タプルのタイプがUPRIGHTであれば、nにkを代入する。このように根付き部分木の最大スコアを記録するSの要素に対応するBの要素からその値を決定するために利用したノードをたどる。つまり、タプルのタイプがDIAGONALである場合のみ、当該インデックスを配列にプッシュすることで最適根付き部分木を得ることができる。   The score of the rooted subtree that maximizes the sum of the values of the nodes below the capacity limit C by calculation by the optimum value calculation unit 32 is stored in the (N + 1) th row of the two-dimensional array S stored in the storage unit 31. Yes. Therefore, first, a column in the (N + 1) th row of S that stores the score of the rooted subtree that maximizes the sum of values below the capacity limit C is determined, and the determined column is set to max_idx (third row). Then, backtracking is performed in order from the N + 1 row and the max_idx column of the two-dimensional array B (9th to 18th rows). If n is a row, m is a column, and the initial position starts from a row where n is N + 1 and m is a max_idx column, and the tuple type stored in B [n] [m] is DIAGONAL, Push index k into array tree. Then, k is substituted for n, and m-cap (A [k]) is substituted for m. If the tuple type is UPRIGHT, substitute k for n. In this way, the node used to determine the value from the B element corresponding to the S element that records the maximum score of the rooted subtree is traced. That is, only when the tuple type is DIAGONAL, the optimal rooted subtree can be obtained by pushing the index into the array.

図4の二次元配列Sでは、容量制限C=10以下の根付き部分木に含まれる各ノードの価値の和の最大値は14である。そこで、図5の二次元配列Bに対応するB[10][10]よりバックトラックをスタートする。最適根付き部分木はプレオーダインデックスが9,8,7,3,2,1のノードからなる根付き部分木なので、v,v,v,v,v,vを選び、出力部50に出力する。 In the two-dimensional array S of FIG. 4, the maximum sum of the values of the nodes included in the rooted subtree with the capacity limit C = 10 or less is 14. Therefore, backtracking is started from B [10] [10] corresponding to the two-dimensional array B in FIG. Since optimal rooted subtree root with subtrees pre order index of nodes of 9,8,7,3,2,1, v 1, v 2, v 6, v 7, v select 8, v 9, the output To the unit 50.

<本発明の実施の形態に係る問題解決装置の作用> <Operation of Problem Solving Device According to Embodiment of the Present Invention>

次に、本発明の実施の形態に係る問題解決装置100の作用について説明する。入力部10において価値と容量を持つノードの各々から構成される木構造と、容量制限Cとを受け付けると、問題解決装置100は、図7に示す問題解決処理ルーチンを実行する。   Next, the operation of the problem solving apparatus 100 according to the embodiment of the present invention will be described. When the input unit 10 receives a tree structure composed of each node having value and capacity and the capacity limit C, the problem solving apparatus 100 executes a problem solving process routine shown in FIG.

まず、ステップS100では、入力部10において受け付けた各ノードをソートして、木構造の根からの深さ優先の順序でプレオーダ順にソートして並べ替える。   First, in step S100, the nodes received by the input unit 10 are sorted, sorted in the order of priority from the root of the tree structure, and rearranged.

次に、ステップS102では、ステップS100で並べ替えた各ノードの数を、Nの値として設定する。   Next, in step S102, the number of each node rearranged in step S100 is set as a value of N.

ステップS104では、記憶部31に記憶された、二次元配列S及び二次元配列Bを初期化する。   In step S104, the two-dimensional array S and the two-dimensional array B stored in the storage unit 31 are initialized.

ステップS106では、スタックsiblingsの初期値としてN+1を積む。   In step S106, N + 1 is accumulated as the initial value of the stack siblings.

ステップS108では、記憶部31に記憶された二次元配列Sの要素S[1][0]に0を格納する。   In step S108, 0 is stored in the element S [1] [0] of the two-dimensional array S stored in the storage unit 31.

ステップS110では、nに1を代入する。   In step S110, 1 is substituted for n.

ステップS112では、nがN以下かを判定し、N以下であればステップS114へ移行し、N以下でなければステップS132へ移行する。   In step S112, it is determined whether n is N or less. If N or less, the process proceeds to step S114, and if not N or less, the process proceeds to step S132.

ステップS114では、nにn+1を代入する。   In step S114, n + 1 is substituted for n.

ステップS116では、n番目のノードと、容量cとの組み合わせの各々について、上記(12)式の1行目に従って、各ノードの価値の和の最大値S[n][c]を計算して、記憶部31に記憶された二次元配列Sの各要素として格納する。   In step S116, for each combination of the nth node and the capacity c, the maximum value S [n] [c] of the sum of the values of the respective nodes is calculated according to the first row of the above equation (12). And stored as each element of the two-dimensional array S stored in the storage unit 31.

ステップS118では、スタックsiblingsの一番上の値はn−1であるか否かを判定し、n−1であればステップS120へ移行し、n−1でなければステップS122へ移行する。   In step S118, it is determined whether or not the top value of the stack siblings is n−1. If n−1, the process proceeds to step S120, and if not n−1, the process proceeds to step S122.

ステップS120では、スタックsiblingsの一番上に積まれた値を取り除く。   In step S120, the value stacked at the top of the stack siblings is removed.

ステップS122では、ノードA[n−1]の右側に存在する兄弟のうち最左の兄弟のプレオーダインデックスをkに代入する。   In step S122, the preorder index of the leftmost sibling among the siblings existing on the right side of the node A [n-1] is substituted for k.

ステップS124では、kがNULLであるか否か(ノードA[n−1]の右側に兄弟がいないか)を判定し、NULLであればステップS126へ移行し、NULLでなければステップS128へ移行する。   In step S124, it is determined whether k is NULL (whether there is no sibling on the right side of node A [n-1]). If NULL, the process proceeds to step S126, and if not NULL, the process proceeds to step S128. To do.

ステップS126では、kにスタックsiblingsの一番上に積まれたインデックスの値を代入する。   In step S126, the index value stacked at the top of the stack siblings is substituted for k.

ステップS128では、kをスタックsiblingsへ積む。   In step S128, k is stacked on the stack siblings.

ステップS130では、上記ステップS122又はS126で得たkに基づいて、各容量cについて、上記(12)式の2行目、3行目に従って、S[k][c]、及びB[k][c]の各要素を決定し、ステップS112へ戻って処理を繰り返す。   In step S130, based on k obtained in step S122 or S126, S [k] [c] and B [k] are set for each capacity c according to the second and third lines of the above equation (12). Each element of [c] is determined, and the process returns to step S112 to repeat the process.

ステップS132では、上記各ステップの処理によって繰り返し計算された計算過程に基づいて、容量制限C以下となる根付き部分木のうち、根付き部分木の各ノードの価値の和が最大となる根付き部分木を出力部50に出力して、処理を終了する。   In step S132, a rooted subtree having a maximum sum of the values of the nodes of the rooted subtree among the rooted subtrees that are less than or equal to the capacity limit C is calculated based on the calculation process that is repeatedly calculated by the process of each step. It outputs to the output part 50 and complete | finishes a process.

上記ステップS116は、図8に示す最大価値計算処理ルーチンによって実現される。   Step S116 is realized by the maximum value calculation processing routine shown in FIG.

以下に説明する最大価値計算処理ルーチンによって、上記(12)式の1行目の再帰式に従って、n番目のノード及び容量cの組み合わせの各々について、当該組み合わせに対する、各ノードの価値の和の最大値S[n][c]を計算して、記憶部31に記憶された配列に格納していく。   According to the maximum value calculation processing routine described below, the maximum sum of the values of the respective nodes for each combination of the nth node and the capacity c is determined according to the recursive expression in the first row of the above expression (12). The value S [n] [c] is calculated and stored in the array stored in the storage unit 31.

図8のステップS200は、容量cの値をc=0とする。   In step S200 of FIG. 8, the value of the capacity c is set to c = 0.

次に、ステップS202では、容量cは容量制限C以下かを判定し、容量制限C以下であればステップS204へ移行し、容量制限C以下でなければ処理を終了する。   Next, in step S202, it is determined whether the capacity c is equal to or less than the capacity limit C. If the capacity limit C is equal to or less than the capacity limit C, the process proceeds to step S204.

ステップS204では、c−cap(A[n−1])が0以上であり、かつS[n][c−cap(A[n−1])]が0以上であるかを判定し、条件を満たしていればステップS206へ移行し、条件を満たしていなければステップS212へ移行する。   In step S204, it is determined whether c-cap (A [n-1]) is 0 or more and S [n] [c-cap (A [n-1])] is 0 or more. If the condition is satisfied, the process proceeds to step S206. If the condition is not satisfied, the process proceeds to step S212.

ステップS206では、S[n][c]よりS[n−1][c−cap(A[n−1])]+p(A[n−1])が大きいかを判定し、条件を満たしていればステップS208へ移行し、条件を満たしていなければステップS212へ移行する。   In step S206, it is determined whether S [n-1] [c-cap (A [n-1])] + p (A [n-1]) is larger than S [n] [c], and the condition is satisfied. If so, the process proceeds to step S208. If the condition is not satisfied, the process proceeds to step S212.

ステップS208では、S[n][c]にS[n−1][c−cap(A[n−1])]+p(A[n−1])の価値のスコアを代入する。   In step S208, the value score of S [n-1] [c-cap (A [n-1])] + p (A [n-1]) is substituted into S [n] [c].

ステップS210では、B[n][c]にインデックスとタイプを表すタプル(n−1、DIAGONAL)を格納する。   In step S210, a tuple (n-1, DIAGONAL) indicating an index and a type is stored in B [n] [c].

そして、ステップS212では、容量cの値をc=c+1とし、ステップS202へ戻って、容量cが容量制限C以下でなくなるまで処理を繰り返す。   In step S212, the value of the capacity c is set to c = c + 1, the process returns to step S202, and the process is repeated until the capacity c is not less than or equal to the capacity limit C.

上記ステップS130は、図9に示す兄弟要素決定処理ルーチンによって実現される。
以下に説明する兄弟要素決定処理ルーチンによって、上記(12)式の2行目、3行目に従って、容量cの各々について、S[k][c]を計算して、記憶部31に記憶された配列に格納していく。
Step S130 is realized by the sibling element determination processing routine shown in FIG.
By the sibling element determination processing routine described below, S [k] [c] is calculated for each of the capacitances c according to the second and third lines of the above equation (12) and stored in the storage unit 31. It stores in the array.

図9のステップS300は、容量cの値をc=0とする。   In step S300 of FIG. 9, the value of the capacity c is set to c = 0.

次に、ステップS302では、容量cは容量制限C以下かを判定し、容量制限C以下であればステップS304へ移行し、容量制限C以下でなければ処理を終了する。   Next, in step S302, it is determined whether the capacity c is equal to or less than the capacity limit C. If the capacity limit C is equal to or less than the capacity limit C, the process proceeds to step S304.

ステップS304では、S[k][c]よりS[n−1][c]が大きいかを判定し、条件を満たしていればステップS306へ移行し、条件を満たしていなければステップS310へ移行する。   In step S304, it is determined whether S [n-1] [c] is larger than S [k] [c]. If the condition is satisfied, the process proceeds to step S306. If the condition is not satisfied, the process proceeds to step S310. To do.

ステップS306では、S[k][c]に、上記最大価値計算処理ルーチンで記憶部31に記憶された二次元配列Sに要素として格納したS[n−1][c]の価値のスコアを代入する。   In step S306, the value score of S [n−1] [c] stored as an element in the two-dimensional array S stored in the storage unit 31 in the maximum value calculation processing routine is added to S [k] [c]. substitute.

ステップS308では、B[n][c]にインデックスとタイプを表すタプル(n−1、UPLIGHT)を格納する。   In step S308, a tuple (n-1, UPLIGHT) indicating an index and a type is stored in B [n] [c].

ステップS310では、容量cの値をc=c+1とし、ステップS302へ戻って、容量cが容量制限C以下でなくなるまで処理を繰り返す。   In step S310, the value of the capacity c is set to c = c + 1, the process returns to step S302, and the process is repeated until the capacity c is not less than or equal to the capacity limit C.

上記ステップS132は、図10に示すバックトラック処理ルーチンによって実現される。   Step S132 is realized by the backtrack processing routine shown in FIG.

図10のステップS400は、根付き部分木の各ノードの価値の和が最大となる根付き部分木の各ノードのインデックスを格納する配列treeを作成し、行nの初期値をN+1に設定する。   Step S400 in FIG. 10 creates an array tree that stores the index of each node of the rooted subtree that maximizes the sum of the values of each node of the rooted subtree, and sets the initial value of row n to N + 1.

次に、ステップS402では、容量制限C以下で価値の和を最大化する根付き部分木のスコアを格納するSのN+1行目における列kを決定し、決定したkをmax_idxとする。   Next, in step S402, a column k in the (N + 1) th row of S that stores the score of the rooted subtree that maximizes the sum of values below the capacity limit C is determined, and the determined k is set to max_idx.

ステップS404では、S[N+1][max_idx]に格納された価値のスコアをmax_valに格納する。   In step S404, the value score stored in S [N + 1] [max_idx] is stored in max_val.

ステップS406では、ステップS404で価値のスコアが格納されたmax_valの値が0未満であるかを判定し、0未満であれば処理を終了し、0未満でなければステップS408へ移行する。   In step S406, it is determined whether the value of max_val in which the value score is stored in step S404 is less than 0. If it is less than 0, the process ends. If not less than 0, the process proceeds to step S408.

ステップS408では、列mにmax_idxの値を代入する。   In step S408, the value of max_idx is assigned to the column m.

ステップS410では、n=1でなく、かつm=0でないかを判定し、条件を満たしていればステップS412へ移行し、条件を満たしていなければ、後述する繰り返し処理で、配列treeにプッシュされたインデックスの各ノードを、各ノードの価値の和が最大となる根付き部分木を構成する各ノードとして出力部50に出力して、処理を終了する。   In step S410, it is determined whether n = 1 and m = 0. If the condition is satisfied, the process proceeds to step S412. If the condition is not satisfied, it is pushed to the array tree by an iterative process described later. Each node of the index is output to the output unit 50 as each node constituting a rooted subtree having the maximum sum of the values of the nodes, and the process is terminated.

ステップS412では、B[n][m]に格納しているインデックス及びタイプを(k,type)にそれぞれ代入する。   In step S412, the index and type stored in B [n] [m] are assigned to (k, type), respectively.

ステップS414では、ステップS412で代入されたtypeがDIAGONALであるかを判定し、DIAGONALであればステップS416へ移行し、DIAGONALでなければステップS422へ移行する。   In step S414, it is determined whether the type substituted in step S412 is DIAGONAL. If it is DIAGONAL, the process proceeds to step S416, and if not DIAGONAL, the process proceeds to step S422.

ステップS416では、配列treeへ、ステップS412で代入されたインデックスkをプッシュする。   In step S416, the index k substituted in step S412 is pushed to the array tree.

ステップS418では、nにインデックスkの値を代入する。   In step S418, the value of index k is substituted for n.

ステップS420では、mにm−cap(A[k])を代入し、ステップS410へ戻って処理を繰り返す。   In step S420, m-cap (A [k]) is substituted for m, and the process returns to step S410 and is repeated.

ステップS422では、nにkを代入し、ステップS410へ戻って、処理を繰り返す。   In step S422, k is substituted for n, and the process returns to step S410 to repeat the process.

以上説明したように、本発明の実施の形態に係る問題解決装置によれば、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の根付き部分木について、各ノードの価値の和の最大値を計算して記憶部31の配列Sに記憶し、各成長段階の根付き部分木について記憶部31に記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含まない根付き部分木とのうち、部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算することで、木制約付きナップサック問題を高速に解くことができる。   As described above, according to the problem solving apparatus according to the embodiment of the present invention, a rooted subtree in which the nth node can be added to each capacity c (0 ≦ c ≦ C) for the nth node. In addition, among the rooted subtrees in which the sum of the capacities of the nodes is equal to the capacity c, the rooted subtree is repeatedly calculated by repeatedly calculating the rooted subtree having the maximum sum of the values of the nodes in the rooted subtree. The rooted subtree that maximizes the sum of the values of the nodes of the tree is gradually grown, and for the rooted subtree of each growth stage, the maximum sum of the values of the nodes is calculated and the array S of the storage unit 31 is calculated. A rooted subtree that can be added to the nth node by calling the maximum sum of the values of the nodes stored in the storage unit 31 for the rooted subtree of each growth stage, and each node The sum of the capacities is the capacity c A rooted subtree including the (n−1) th node to be equal and a rooted subtree to which the nth node can be added, and the sum of the capacities of the nodes is equal to the capacity c. By recursively calculating a rooted subtree that has the maximum value of the nodes of the subtree among the rooted subtrees that are not included, the tree-constrained knapsack problem can be solved at high speed.

また、図3のAlgorithm1から明らかなように本発明は容量C+1の配列をN+1個用意し、値を決めるだけなので、その計算量はO(NC)である。   Further, as apparent from Algorithm 1 in FIG. 3, the present invention only prepares N + 1 arrays of capacitors C + 1 and determines the value, so the amount of calculation is O (NC).

なお、本発明は、上述した実施形態に限定されるものではなく、この発明の要旨を逸脱しない範囲内で様々な変形や応用が可能である。   Note that the present invention is not limited to the above-described embodiment, and various modifications and applications are possible without departing from the gist of the present invention.

10 入力部
20 演算部
30 ソート部
31 記憶部
32 最適値計算部
34 バックトラック部
50 出力部
100 問題解決装置
DESCRIPTION OF SYMBOLS 10 Input part 20 Operation part 30 Sort part 31 Storage part 32 Optimal value calculation part 34 Back track part 50 Output part 100 Problem solving apparatus

Claims (5)

価値と容量を持つノードの各々から構成される木構造から、容量制限C以下で価値を最大化する根付き部分木を選択する木制約付きナップサック問題を解決する問題解決装置であって、
前記木構造を構成する各ノードを、前記木構造の根からの深さ優先の順序で並べ替えるソート部と、
前記ソート部により並べ替えられた各ノードの順序に従って、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の前記根付き部分木について、各ノードの価値の和の最大値を計算して記憶部に記憶する最適値計算部と、
前記最適値計算部によって繰り返し計算された計算過程に基づいて、前記容量制限C以下となる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を出力するバックトラック部とを含み、
前記最適値計算部は、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を計算するとき、各成長段階の前記根付き部分木について前記記憶部に記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる前記n−1番目のノードを含まない根付き部分木とのうち、前記部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算する
問題解決装置。
A problem solving apparatus that solves a tree-constrained knapsack problem that selects a rooted subtree that maximizes a value below a capacity limit C from a tree structure composed of nodes having value and capacity,
A sorting unit that rearranges each node constituting the tree structure in a depth-first order from the root of the tree structure;
In accordance with the order of the nodes rearranged by the sorting unit, for the nth node, a rooted subtree that can add the nth node to each capacity c (0 ≦ c ≦ C), and Of the rooted subtrees in which the sum of the node capacities is equal to the capacity c, by repeatedly calculating the rooted subtree having the maximum sum of the values of the nodes in the rooted subtree, An optimal value calculation unit that gradually grows a rooted subtree that maximizes the sum of values, calculates a maximum sum of values of each node for the rooted subtree in each growth stage, and stores the value in a storage unit; ,
Based on a calculation process repeatedly calculated by the optimum value calculation unit, a rooted subtree having a maximum sum of values of the nodes of the rooted subtree among the rooted subtrees having the capacity limit C or less is output. Including a backtrack section,
The optimum value calculation unit is a rooted subtree to which the nth node can be added, and the value of each node of the rooted subtree among the rooted subtrees in which the sum of the capacities of the nodes is equal to the capacity c When the rooted subtree with the largest sum is calculated, the maximum value of the sum of the values of the nodes stored in the storage unit for the rooted subtree in each growth stage can be called to add the nth node A rooted subtree that includes an (n-1) th node whose sum of capacities of each node is equal to the capacity c, and a rooted subtree to which the nth node can be added, and Among the rooted subtrees not including the (n-1) th node whose sum of capacities of the nodes is equal to the capacity c, the rooted subtree having the maximum sum of the values of the nodes of the subtree is recursively. Calculate problem solving equipment Place.
前記最適値計算部は、以下の(1)式を用いて、前記記憶部に記憶された、前記n番目のノード及び前記容量cの組み合わせの各々に対する、各ノードの価値の和の最大値S[n][c]を格納する配列を初期化し、
前記n番目のノード及び前記容量cの組み合わせの各々について、以下の(2)式を用いて、前記組み合わせに対する、各ノードの価値の和の最大値S[n][c]を計算して、前記記憶部に記憶された前記配列に格納する請求項1記載の問題解決装置。
ただし、A[n]は、n番目のノードを表し、関数cap(A[n])は、n番目のノードの容量を表し、p(A[n])は、n番目のノードの価値を表し、関数next_undesc(h)は、h+1番目以降のノードのうち、h番目のノードの子孫でない最初のノードのインデックスを返す関数を表す。
The optimum value calculation unit uses the following equation (1) to calculate the maximum value S of the sum of the values of the nodes for each combination of the nth node and the capacity c stored in the storage unit. Initialize an array to store [n] [c];
For each combination of the nth node and the capacity c, the maximum value S [n] [c] of the sum of the values of each node for the combination is calculated using the following equation (2): The problem solving apparatus according to claim 1, wherein the problem solving apparatus stores the data in the array stored in the storage unit.
However, A [n] represents the nth node, the function cap (A [n]) represents the capacity of the nth node, and p (A [n]) represents the value of the nth node. The function next_undesc (h) represents a function that returns the index of the first node that is not a descendant of the h-th node among the h + 1 and subsequent nodes.
価値と容量を持つノードの各々から構成される木構造から、容量制限C以下で価値を最大化する根付き部分木を選択する木制約付きナップサック問題を解決する問題解決装置における問題解決方法であって、
ソート部が、前記木構造を構成する各ノードを、前記木構造の根からの深さ優先の順序で並べ替えるステップと、
最適値計算部が、前記ソート部により並べ替えられた各ノードの順序に従って、n番目のノードについて、各容量c(0≦c≦C)に対し、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を繰り返し計算することにより、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を漸次的に成長させ、各成長段階の前記根付き部分木について、各ノードの価値の和の最大値を計算して記憶部に記憶するステップと、
バックトラック部が、前記最適値計算部によって繰り返し計算された計算過程に基づいて、前記容量制限C以下となる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を出力するステップとを含み、
前記最適値計算部によって計算するステップは、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる根付き部分木のうち、前記根付き部分木の各ノードの価値の和が最大となる根付き部分木を計算するとき、各成長段階の前記根付き部分木について前記記憶部に記憶した、各ノードの価値の和の最大値を呼び出して、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなるn−1番目のノードを含む根付き部分木と、n番目のノードを追加できる根付き部分木であって、かつ、各ノードの容量の和が容量cと等しくなる前記n−1番目のノードを含まない根付き部分木とのうち、前記部分木の各ノードの価値の和が最大となる根付き部分木を再帰的に計算する
問題解決方法。
A problem solving method in a problem solving apparatus for solving a tree-constrained knapsack problem in which a rooted subtree that maximizes a value with a capacity limit C or less is selected from a tree structure composed of nodes each having value and capacity. ,
A step of sorting the nodes constituting the tree structure in a depth-first order from the root of the tree structure;
The optimal value calculation unit is a rooted subtree that can add the nth node for each capacity c (0 ≦ c ≦ C) for the nth node according to the order of the nodes rearranged by the sorting unit. In addition, among the rooted subtrees in which the sum of the capacities of the nodes is equal to the capacity c, the rooted subtree having the maximum sum of the values of the nodes in the rooted subtree is repeatedly calculated, whereby the rooted The rooted subtree that maximizes the sum of the values of each node in the subtree is gradually grown, and the maximum sum of the values of each node is calculated and stored in the storage unit for the rooted subtree in each growth stage. And steps to
Based on the calculation process in which the backtrack unit is repeatedly calculated by the optimum value calculation unit, among the rooted subtrees that are less than or equal to the capacity limit C, the rooting that maximizes the sum of the values of the nodes of the rooted subtree Outputting a subtree,
The step of calculating by the optimum value calculating unit is a rooted subtree to which an nth node can be added, and among the rooted subtrees in which the sum of the capacities of each node is equal to the capacity c, the rooted subtree When calculating a rooted subtree that maximizes the sum of the values of each node, the maximum value sum of the values of each node stored in the storage unit for the rooted subtree of each growth stage is called, A rooted subtree to which nodes can be added, and a rooted subtree including the (n-1) th node in which the sum of the capacities of the nodes is equal to the capacity c, and a rooted subtree to which the nth node can be added. And a rooted subtree in which the sum of the values of the nodes of the subtree is the largest among the rooted subtrees not including the (n−1) th node whose sum of capacities of the nodes is equal to the capacity c. Re Problem-solving method to calculate.
前記最適値計算部によって計算するステップは、以下の(4)式を用いて、前記記憶部に記憶された、前記n番目のノード及び前記容量cの組み合わせの各々に対する、各ノードの価値の和の最大値S[n][c]を格納する配列を初期化し、
前記n番目のノード及び前記容量cの組み合わせの各々について、以下の(5)式を用いて、前記組み合わせに対する、各ノードの価値の和の最大値S[n][c]を計算して、前記記憶部に記憶された前記配列に格納する請求項3記載の問題解決方法。
ただし、A[n]は、n番目のノードを表し、関数cap(A[n])は、n番目のノードの容量を表し、p(A[n])は、n番目のノードの価値を表し、関数next_undesc(h)は、h+1番目以降のノードのうち、h番目のノードの子孫でない最初のノードのインデックスを返す関数を表す。
The step of calculating by the optimum value calculating unit uses the following equation (4) to sum the value of each node for each combination of the nth node and the capacity c stored in the storage unit: Initialize an array for storing the maximum value S [n] [c] of
For each of the combinations of the n-th node and the capacitance c, the maximum value S [n] [c] of the sum of the values of the nodes for the combination is calculated using the following equation (5): The problem solving method according to claim 3, wherein the problem is stored in the array stored in the storage unit.
However, A [n] represents the nth node, the function cap (A [n]) represents the capacity of the nth node, and p (A [n]) represents the value of the nth node. The function next_undesc (h) represents a function that returns the index of the first node that is not a descendant of the h-th node among the h + 1 and subsequent nodes.
コンピュータを、請求項1又は2に記載の問題解決装置を構成する各部として機能させるためのプログラム。   The program for functioning a computer as each part which comprises the problem-solving apparatus of Claim 1 or 2.
JP2014146547A 2014-07-17 2014-07-17 Problem solving apparatus, method, and program Active JP6190773B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2014146547A JP6190773B2 (en) 2014-07-17 2014-07-17 Problem solving apparatus, method, and program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2014146547A JP6190773B2 (en) 2014-07-17 2014-07-17 Problem solving apparatus, method, and program

Publications (2)

Publication Number Publication Date
JP2016024522A JP2016024522A (en) 2016-02-08
JP6190773B2 true JP6190773B2 (en) 2017-08-30

Family

ID=55271257

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2014146547A Active JP6190773B2 (en) 2014-07-17 2014-07-17 Problem solving apparatus, method, and program

Country Status (1)

Country Link
JP (1) JP6190773B2 (en)

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP2244633A4 (en) * 2008-02-14 2013-10-23 Penn State Res Found Medical image reporting system and method

Also Published As

Publication number Publication date
JP2016024522A (en) 2016-02-08

Similar Documents

Publication Publication Date Title
US7627604B2 (en) Method for handling tree-type data structure, information processing device, and program
EP2140376A1 (en) Method and system for approximate string matching
US8996436B1 (en) Decision tree classification for big data
US9147168B1 (en) Decision tree representation for big data
He et al. A framework for succinct labeled ordinal trees over large alphabets
Baswana et al. Incremental algorithm for maintaining a DFS tree for undirected graphs
JP6190773B2 (en) Problem solving apparatus, method, and program
US10795920B2 (en) Information processing device, information processing method, and computer-readable storage medium
US9122997B1 (en) Generating attribute-class-statistics for decision trees
Demaine et al. Polylogarithmic fully retroactive priority queues via hierarchical checkpointing
JP6232390B2 (en) Text summarization apparatus, method, and program
CN108021695A (en) FP-Growth big data Frequent Itemsets Mining Algorithms based on Spark frames
KR101085967B1 (en) Linear time Top-k Sort by
US20070156769A1 (en) Partition elimination system for a database that uses a multi-level partitioning definition
Bender et al. Online List Labeling: Breaking the Barrier
Galcik et al. Advanced Priority Queues in the OPTICS Clustering Algorithm
CN110175198A (en) Mining Frequent Itemsets and device based on MapReduce and array
Sheela et al. Survey on Mining Association Rule with Data Structures
Rangan Randomized dictionary structures
Kaldewaij et al. Leaf trees
Morihata et al. A practical tree contraction algorithm for parallel skeletons on trees of unbounded degree
Hon et al. Compressed dictionary matching with one error
Kosmatopoulos et al. Dynamic Processing of Dominating Queries with Performance Guarantees.
Arnarson et al. PermPAL-Permutation pattern avoidance library
Arora et al. Iterative method for recreating a binary tree from its traversals

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20160721

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20170728

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20170801

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20170807

R150 Certificate of patent or registration of utility model

Ref document number: 6190773

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

S533 Written request for registration of change of name

Free format text: JAPANESE INTERMEDIATE CODE: R313533

R350 Written notification of registration of transfer

Free format text: JAPANESE INTERMEDIATE CODE: R350