CN115221460B - Method for solving ordered knapsack problem segmentation dynamic programming under limited resources - Google Patents

Method for solving ordered knapsack problem segmentation dynamic programming under limited resources Download PDF

Info

Publication number
CN115221460B
CN115221460B CN202211140581.XA CN202211140581A CN115221460B CN 115221460 B CN115221460 B CN 115221460B CN 202211140581 A CN202211140581 A CN 202211140581A CN 115221460 B CN115221460 B CN 115221460B
Authority
CN
China
Prior art keywords
backpack
state
articles
state array
stage
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
CN202211140581.XA
Other languages
Chinese (zh)
Other versions
CN115221460A (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.)
Zhejiang Baorong Technology Co ltd
Original Assignee
Zhejiang Baorong Technology Co ltd
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 Zhejiang Baorong Technology Co ltd filed Critical Zhejiang Baorong Technology Co ltd
Priority to CN202211140581.XA priority Critical patent/CN115221460B/en
Publication of CN115221460A publication Critical patent/CN115221460A/en
Application granted granted Critical
Publication of CN115221460B publication Critical patent/CN115221460B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/11Complex mathematical operations for solving equations, e.g. nonlinear equations, general mathematical optimization problems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/16Matrix or vector computation, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/04Forecasting or optimisation specially adapted for administrative or management purposes, e.g. linear programming or "cutting stock problem"
    • G06Q10/047Optimisation of routes or paths, e.g. travelling salesman problem

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Mathematical Optimization (AREA)
  • Mathematical Analysis (AREA)
  • Computational Mathematics (AREA)
  • Pure & Applied Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Business, Economics & Management (AREA)
  • General Engineering & Computer Science (AREA)
  • Human Resources & Organizations (AREA)
  • Operations Research (AREA)
  • Strategic Management (AREA)
  • Algebra (AREA)
  • Databases & Information Systems (AREA)
  • Economics (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Game Theory and Decision Science (AREA)
  • Development Economics (AREA)
  • Marketing (AREA)
  • Quality & Reliability (AREA)
  • Tourism & Hospitality (AREA)
  • General Business, Economics & Management (AREA)
  • Computing Systems (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a method for solving a sectionalized dynamic planning of an ordered knapsack problem under limited resources, which comprises the following steps: for the input data, the number n of articles, the serial number i of each article and the weight are preset
Figure 11571DEST_PATH_IMAGE001
And price
Figure 25663DEST_PATH_IMAGE002
The backpack bears the weight W; setting the maximum storage of the state array F; reading the size of the available memory, and determining the element number S of the state array F through the minimum value between the maximum storage of the state array and the size of the available memory; sequencing the articles from light to heavy, recording the sequence number of the sequenced articles as j, and recording the corresponding relation between the sequence number j and the sequence number i; defining the number of rows and columns of the state array as n
Figure 823199DEST_PATH_IMAGE003
(ii) a Defining the load-bearing capacity of the backpack in the t stage,sequentially judging whether each article is selected to be put into the backpack or not, and calculating the total price of the articles in the backpack at the t stage; if the first preset condition is met, redefining the load bearing of the backpack in the t +1 stage, calculating the total price of the articles in the backpack in the t +1 stage until the second preset condition is met, and outputting a result.

Description

Method for solving ordered knapsack problem segmentation dynamic programming under limited resources
Technical Field
The invention relates to the field of data processing, in particular to a method for solving a sectionalized dynamic planning of an ordered knapsack problem under limited resources.
Background
The knapsack problem is a NP-complete problem with combinatorial optimization. Mathematically, it means that given a set of items, each having its own weight and price, we choose how to maximize the total price of the items within a defined total weight, although weight and price can be replaced by any other arbitrary parameters. Wherein, each kind of article can only select the problem of 0 or 1 backpack, which is called the problem of 0-1 backpack.
At present, the problem of the 0-1 knapsack is generally solved by dynamic programming, and the basic idea is as follows: for each item, either a backpack or no backpack is placed; in the conventional dynamic programming solution knapsack problem, the items do not need to be sorted, and when the ith item is selected, the item is selected not to be put when the total price selected to be put in is the same as the item selected not to be put in.
At present, a large amount of data processing work is mainly executed by a computer, and in the data processing process, for solving a knapsack problem by traditional dynamic planning, if the maximum total price needs to be solved, and the putting state of each item needs to be solved, a two-dimensional array needs to be used as a state variable. When the total price W =1 hundred million and the number n =1 ten thousand, int32 is used for the state variable element, and the state array occupies W × n × 4byte ≈ 3725.29GB of memory. This is obviously what a general computer cannot bear, that is, when the data volume is large, the existing knapsack problem solving method will generate a huge amount of memory requirements, which severely restricts the data processing efficiency, so a new method needs to be provided to reduce the memory occupation and improve the data processing efficiency.
Disclosure of Invention
Aiming at the problem that the memory occupation is large when the ordered 0-1 knapsack problem is processed in the prior art, the invention provides a segmented dynamic planning solving method for the ordered knapsack problem under the limited resource, which can perform segmented processing by optimizing the processing flow under the condition of limited memory resource, reduce the memory occupation and improve the operation and processing efficiency of a computer.
The invention discloses a method for solving a sectionalized dynamic planning of an ordered knapsack problem under limited resources, which comprises the following steps:
a1: for the input data, the number n of articles, the serial number i of each article and the weight are preset
Figure 298855DEST_PATH_IMAGE001
And price
Figure 893303DEST_PATH_IMAGE002
Backpack bearing W, wherein
Figure 75672DEST_PATH_IMAGE003
A2: setting the maximum storage of the state array F;
a3: reading the size of the available memory, and determining the element number S of the state array F through the minimum value between the maximum storage of the state array and the size of the available memory;
a4: sequencing the articles from light to heavy, recording the sequence number of the sequenced articles as j, and recording the corresponding relation between the sequence number j and the sequence number i;
a5: define the number of rows n, columns c, and state array F as
Figure 74371DEST_PATH_IMAGE004
A6: defining the load bearing of the backpack in the t stage, sequentially judging whether each article is selected to be put into the backpack, and calculating the total price of the articles in the backpack in the t stage; if the first preset condition is met, redefining the load bearing of the backpack in the t +1 stage, calculating the total price of the articles in the backpack in the t +1 stage until the second preset condition is met, and outputting a result.
In the present invention, the term "article" in the article quantity refers to any data and information that can be counted, and is not limited to a physical article, wherein the weight does not necessarily refer to a physical weight, the price does not necessarily refer to a price in economy, and these two parameters can be replaced by any parameters. The size of the available memory is actually subtracted by a safety threshold that needs to be reserved to allow the server to operate stably, which will not be described below.
When the backpack problem is solved, the state array is created by reading the size of the memory, so that the memory overflow and overlong operation time are avoided; and in the process, because all data are not required to be called simultaneously, the memory occupation is small, the operation pressure of a computer can be reduced, and the processing efficiency is improved.
Preferably, the process of step A5 comprises: defining the number of rows n, the number of columns c is S/n and rounded down, the number of columns of the state array is 1,2, \ 8230, c represents the grade of the load-bearing of the backpack and is marked as
Figure 864484DEST_PATH_IMAGE005
Preferably, in step A5, the elements in the state array F are denoted as F [ i [ ]][j]Representing the element in the ith row and jth column of the state array F, such that
Figure 869480DEST_PATH_IMAGE006
And not stored in the state array. These steps are the underlying definition process that can help to clarify the relationships between data.
Preferably, in step A6, the initial time t is 1, and the first-stage backpack load is defined as
Figure 765411DEST_PATH_IMAGE007
Unit of
Figure 341535DEST_PATH_IMAGE008
Rounded down, weight of each article
Figure 218356DEST_PATH_IMAGE009
And rounding upwards.
Preferably, in step A6, the sequentially determining whether each item is selected to be put in a backpack includes:
put the 1 st article into the backpack, fill the first row of state array F [1 ]]When is coming into contact with
Figure 616322DEST_PATH_IMAGE010
When the utility model is used, the water is discharged,
Figure 881606DEST_PATH_IMAGE011
otherwise
Figure 753266DEST_PATH_IMAGE012
Selecting whether to place the jth item in the backpack, and regarding the state array elements
Figure 727169DEST_PATH_IMAGE013
In other words, the new state is
Figure 76897DEST_PATH_IMAGE014
When it comes to
Figure 61998DEST_PATH_IMAGE015
When the item j is selected to be put into the backpack, otherwise, the item j is not selected to be put into the backpack, and the j-th row state array F [ j ] is filled in sequence];
Last element of slave state array
Figure 838980DEST_PATH_IMAGE016
Begin to judge whether item j is selected for putting into the backpack, if
Figure 693322DEST_PATH_IMAGE017
Then article
Figure 830430DEST_PATH_IMAGE018
The corresponding item serial number i is recorded into a serial number list X of the loaded backpack, and the remaining state sub-array is
Figure 693475DEST_PATH_IMAGE019
If it is determined that
Figure 883500DEST_PATH_IMAGE020
Figure 693980DEST_PATH_IMAGE021
The remaining state sub-array is
Figure 523526DEST_PATH_IMAGE022
Remaining state subarray
Figure 634221DEST_PATH_IMAGE023
The submatrix is composed of the 1 st row to the ith row and the 1 st column to the jth column of the original state array or the residual state subarray;
for any remaining state subarray, assume it to be
Figure 947951DEST_PATH_IMAGE024
When is coming into contact with
Figure 511306DEST_PATH_IMAGE025
When, when
Figure 3599DEST_PATH_IMAGE026
Figure 968799DEST_PATH_IMAGE027
Then the item serial number i corresponding to the item j is recorded in the serial number list X of the backpack to be loaded, and the new remaining state sub-array
Figure 992906DEST_PATH_IMAGE028
If it is determined that
Figure 892556DEST_PATH_IMAGE029
New remaining state subarrays
Figure 551988DEST_PATH_IMAGE030
This step is repeated until the new remaining state subarray is empty.
Preferably, in step A6, the first preset condition is:
Figure 371695DEST_PATH_IMAGE031
removing the remaining articles after the preceding stage
Figure 956916DEST_PATH_IMAGE032
The number of which is still noted
Figure 343863DEST_PATH_IMAGE033
Sequence numbers are still noted as j, j =1,2, \8230;,
Figure 180887DEST_PATH_IMAGE033
recording the corresponding relation between j and original serial number i of the article, and the new number of rows
Figure 996046DEST_PATH_IMAGE034
If, if
Figure 14818DEST_PATH_IMAGE031
Defining the load bearing capacity of the backpack in the t stage as
Figure 508903DEST_PATH_IMAGE035
Unit of
Figure 126181DEST_PATH_IMAGE036
Weight of each item remaining
Figure 920480DEST_PATH_IMAGE037
Preferably, in step A6, the second preset condition is:
Figure 719940DEST_PATH_IMAGE038
repeatedly executing computing tasks in different stages until
Figure 107846DEST_PATH_IMAGE038
Defining the backpack to bear weight at this stage
Figure 418753DEST_PATH_IMAGE039
Is still marked as
Figure 939995DEST_PATH_IMAGE035
Calculating the total price of items in a backpack
Figure 913286DEST_PATH_IMAGE040
And outputting a sequence number list X and a total price P of the articles contained in the backpack.
The substantial effects of the invention include: the problem of the knapsack is solved under the condition of limited resources and limited time, and the capability of using the knapsack problem to solve the actual problem is improved; the invention can be suitable for solving the knapsack problem with limited resources and limited time, limits the occupation of the memory by the state data to S data elements, obviously reduces the time complexity, reduces the occupation of the memory, can reduce the operation pressure of a computer and improves the processing efficiency.
Drawings
FIG. 1 is a flow chart of an embodiment of the present invention;
FIG. 2 is a memory comparison diagram according to an embodiment of the present invention;
FIG. 3 is a time comparison graph of an embodiment of the present invention;
FIG. 4 is an error trend graph of an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions will be clearly and completely described below with reference to the embodiments, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be understood that, in various embodiments of the present invention, the sequence numbers of the processes do not mean the execution sequence, and the execution sequence of the processes should be determined by the functions and the internal logic of the processes, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
It should be understood that in the present application, "comprising" and "having" and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be understood that, in the present invention, "a plurality" means two or more. "and/or" is only an association relationship describing an associated object, and means that there may be three relationships, for example, a and/or B, and may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. "comprising a, B and C", "comprising a, B, C" means that all three of a, B, C are comprised, "comprising a, B or C" means comprising one of three of a, B, C, "comprising a, B and/or C" means comprising any 1 or any 2 or 3 of three of a, B, C.
The technical solution of the present invention will be described in detail below with specific examples. Embodiments may be combined with each other and some details of the same or similar concepts or processes may not be repeated in some embodiments.
Example (b):
a method for solving a segmented dynamic programming of an ordered knapsack problem under limited resources is disclosed, as shown in FIG. 1, and comprises the following steps:
a1: for the input data, the number n of articles, the serial number i of each article and the weight are preset
Figure 647543DEST_PATH_IMAGE001
And price
Figure 502497DEST_PATH_IMAGE002
Backpack bearing W, wherein
Figure 982372DEST_PATH_IMAGE003
A2: setting the maximum storage of the state array F;
a3: reading the size of the available memory, and determining the element number S of the state array F through the minimum value between the maximum storage of the state array and the size of the available memory;
a4: sequencing the articles from light to heavy, recording the sequence number of the sequenced articles as j, and recording the corresponding relation between the sequence number j and the sequence number i;
a5: defining the number of rows and columns of the state array as n
Figure 516777DEST_PATH_IMAGE041
The state array F is noted
Figure 738330DEST_PATH_IMAGE004
A6: defining the load bearing of the backpack in the t stage, sequentially judging whether each article is selected to be put into the backpack or not, and calculating the total price of the articles in the backpack in the t stage; if the first preset condition is met, redefining the load bearing of the backpack in the t +1 stage, calculating the total price of the articles in the backpack in the t +1 stage until the second preset condition is met, and outputting a result.
The present embodiment will explain and exemplify the above process by using actual data, wherein the backpack bears W =60, the number of items n =7, the size of the memory required by the state array = W × n × 4byte =60 × 7 × 4byte =1680byte, and the weight and price of each item are shown in table 1:
Figure 256030DEST_PATH_IMAGE042
in weight order, as shown in table 2:
Figure 613849DEST_PATH_IMAGE043
when the stage is not divided:
item 2 is first placed in the backpack, weighing 5, and pricing 21, at which time the state matrix occupies memory =60 x 1 x 4byte =240byte.
Then, considering whether or not the item 5 is placed in the backpack, a new state matrix is formed, which occupies memory =60 × 2 × 4byte =480byte.
This was repeated until all articles underwent one round of consideration, the state matrix occupied memory =60 × 7 × 4byte =1680byte, and a total of 60 × 7 comparisons of state values were made.
The optimal solution is to load item 2, item 5, item 1, item 4, item 3 into the backpack's total weight 53, total price 97.
In the staged stage:
assuming S = 180/4 bytes, then
Figure 46450DEST_PATH_IMAGE044
(ii) a The weights of the articles in the first stage are shown in table 3:
Figure 752369DEST_PATH_IMAGE045
placing items in the backpack in the same order as without segmentation can result in a one-stage state matrix as in table 4:
Figure 60378DEST_PATH_IMAGE046
memory required for the state matrix =7 × 6 × 4byte =168byte.
The solution obtained in the first stage is therefore to place the items 2, 5, 1, 4 in the backpack, the total price 84, the total weight 38 (note that here the original weight needs to be calculated), the remaining weight 22 of the backpack, and at this point the state matrix can be released.
Entering the second stage of the process,
Figure 679228DEST_PATH_IMAGE047
after rejecting articles having a weight greater than 22
Figure 407365DEST_PATH_IMAGE048
Figure 335001DEST_PATH_IMAGE049
Figure 72799DEST_PATH_IMAGE050
Therefore, to remember
Figure 670789DEST_PATH_IMAGE051
Second stage articles are as in table 5:
Figure 465701DEST_PATH_IMAGE052
sequentially putting articles into the back state matrix of the backpack; the memory required for the available state matrix =1 × 22 × 4byte =88byte. The result of the second stage is to place the item 3 in the backpack, total price 13, total weight 15; the phase cycle ends.
The final solution obtained by combining the two stages is to load the items 2, 5, 1, 4, 3 into the backpack at a total weight of 53, a total price of 97, consistent with the results obtained without segmentation.
Of course, as the number of items increases and the load of the backpack increases, the proportion of completely consistent plans decreases, but with the exception of the extreme case, the total price deviation is always in a small range, and the difference between the memory requirement and the time requirement becomes more obvious.
For example, when the backpack bears a load of 100000 and the weight and price of the item are random numbers of 1-10000, the memory pair of non-staged and staged such as shown in fig. 2, in which the data representing the staged data with obvious segmented broken lines, can be seen to have a significant reduction in memory usage.
When the backpack bears 100000 weight and the weight and price of the item are random numbers of 1-10000, the time is obviously reduced when the time is not divided into stages and is divided into stages as shown in fig. 3, wherein the data of the divided stages are represented by a broken line which is obviously divided.
When the load of the backpack is 100000 and the weight and price of the article are random numbers of 1-10000, the error trend of the non-stage and the stage is shown in figure 4, and the error is still very small.
In summary, the technical improvement of the present embodiment mainly includes two points:
the first point is to satisfy the ordering requirement by ordering and coverage placement. In the conventional dynamic programming solution knapsack problem, the items do not need to be sorted, and when the ith item is selected, the item is selected not to be put when the total price selected to be put in is the same as the item selected not to be put in. According to the invention, firstly, the alternative articles are sorted according to weight, then when the ith article is selected, if the total price is equal, the article i is selected to be put in, and the original scheme is covered, so that the scheme containing articles with larger weight replaces the scheme containing articles with smaller weight at the same total price.
The second point is to create the state array by reading the memory size, thereby avoiding memory overflow and lengthy run time. In the conventional dynamic programming for solving the knapsack problem, if the maximum total price needs to be solved and the putting state of each item needs to be solved at the same time, a two-dimensional array needs to be used as a state variable. When W =1 hundred million and n =1 ten thousand, int32 is used as a state variable element, and occupation of a state array is required
Figure 203143DEST_PATH_IMAGE053
. Meanwhile, the updating of each state variable element is a plurality of comparison and assignment, and the time complexity is O (Wn). The invention sets the upper limit of the memory, reads the size of the server memory, determines the maximum quantity S of the storable data elements by taking the minimum value of the upper limit and the size of the server memory to limit the size of the state array, and sets the state array as
Figure 603687DEST_PATH_IMAGE054
. Taking U = rounding down (W/c) as 1 unit, making the load of the backpack at the current stage as c, and making the articlesWeight (D)
Figure 56184DEST_PATH_IMAGE055
And solving by using a coverage dynamic planning method, then taking the residual bearing of the backpack after solving as a new bearing, and taking the article which is not selected to be put in as a new alternative article to repeat the process. The solution limits the occupation of the state array to the memory within S data elements, obviously reduces the time complexity, and is meaningful in many scenes compared with the method which cannot solve the problem although the final precision is reduced to some extent.
Through the description of the above embodiments, those skilled in the art will understand that, for convenience and simplicity of description, only the division of the above functional modules is used as an example, and in practical applications, the above function distribution may be completed by different functional modules according to needs, that is, the internal structure of a specific device is divided into different functional modules to complete all or part of the above described functions.
In the embodiments provided in the present application, it should be understood that the disclosed structures and methods may be implemented in other ways. For example, the above-described embodiments with respect to structures are merely illustrative, and for example, a module or a unit may be divided into only one logic function, and may have another division manner in actual implementation, for example, a plurality of units or components may be combined or may be integrated into another structure, or some features may be omitted or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, structures or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may be one physical unit or a plurality of physical units, may be located in one place, or may be distributed to a plurality of different places. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit may be implemented in the form of hardware, or may also be implemented in the form of a software functional unit.
The integrated unit, if implemented as a software functional unit and sold or used as a separate product, may be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present application may be essentially or partially contributed to by the prior art, or all or part of the technical solutions may be embodied in the form of a software product, where the software product is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the methods of the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily think of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (5)

1. A method for solving the segmented dynamic programming of the ordered knapsack problem under the limited resources is characterized by comprising the following steps:
a1: for the input data, the number n of articles, the serial number i of each article and the weight are preset
Figure 912548DEST_PATH_IMAGE001
And price
Figure 875694DEST_PATH_IMAGE002
Backpack bearing W, wherein
Figure 389852DEST_PATH_IMAGE003
A2: setting the maximum storage of the state array F;
a3: reading the size of the available memory, and determining the element number S of the state array F through the minimum value between the maximum storage of the state array and the size of the available memory;
a4: sequencing the articles according to the weight from light to heavy, recording the serial number of the sequenced articles as j, and recording the corresponding relation between the serial number j and the serial number i;
a5: defining the number of rows and columns of the state array as n
Figure 581799DEST_PATH_IMAGE004
The state array F is noted
Figure 927329DEST_PATH_IMAGE005
A6: defining the load bearing of the backpack in the t stage, sequentially judging whether each article is selected to be put into the backpack or not, and calculating the total price of the articles in the backpack in the t stage; if the first preset condition is met, redefining the load bearing of the backpack in the t +1 stage, calculating the total price of the articles in the backpack in the t +1 stage until the second preset condition is met, and outputting a result;
the first preset condition is as follows:
Figure 484213DEST_PATH_IMAGE006
after the previous stage is completed, the residual articles are removed
Figure 751246DEST_PATH_IMAGE007
Of the articles, the number of which is still noted
Figure 746884DEST_PATH_IMAGE008
The serial number is still marked as j,
Figure 150183DEST_PATH_IMAGE009
recording the corresponding relation between j and original serial number i of the article, and the new number of columns
Figure 691017DEST_PATH_IMAGE010
If, if
Figure 179767DEST_PATH_IMAGE011
Defining the load bearing capacity of the backpack in the t stage as
Figure 713517DEST_PATH_IMAGE012
Unit of
Figure 768061DEST_PATH_IMAGE013
Weight of each item remaining
Figure 932326DEST_PATH_IMAGE014
The second preset condition is as follows:
Figure 970689DEST_PATH_IMAGE015
repeatedly executing different stages of computing tasks until
Figure 980233DEST_PATH_IMAGE015
Defining the load bearing capacity of the backpack at this stage as
Figure 669709DEST_PATH_IMAGE016
Is still marked as
Figure 739297DEST_PATH_IMAGE017
Calculating total price of items in backpack
Figure 264956DEST_PATH_IMAGE018
And outputting a sequence number list X and a total price P of the articles contained in the backpack.
2. The method for solving the segmented dynamic programming of the ordered knapsack problem under the limited resources according to claim 1, wherein the process of the step A5 comprises: defining the row number n of the state array, the column number c of the state array being S/n rounded down, the column number of the state array being 1,2, \ 8230;, c represents the grade of the backpack load, and is recorded as
Figure 78191DEST_PATH_IMAGE019
3. The method for solving the segmented dynamic programming of the ordered knapsack problem under the limited resources according to claim 1, wherein in the step A5, the elements in the state array F are recorded as F [ i [ ]][j]Representing the element in the ith row and jth column of the state array F, such that
Figure 372906DEST_PATH_IMAGE020
And is not stored in the state array.
4. The method according to claim 1, wherein in step A6, t is 1 at the beginning, and the backpack load in the first stage is defined as
Figure 878974DEST_PATH_IMAGE021
Unit of
Figure 626350DEST_PATH_IMAGE022
Rounded down, weight of each article
Figure 243276DEST_PATH_IMAGE023
And rounding up.
5. The method according to claim 4, wherein the step A6 of sequentially determining whether each item is selected to be put into the backpack includes:
put the 1 st article into the backpack, fill the first row of state array F [1 ]]When is coming into contact with
Figure 143230DEST_PATH_IMAGE024
When the utility model is used, the water is discharged,
Figure DEST_PATH_IMAGE025
otherwise
Figure 820199DEST_PATH_IMAGE026
Selecting whether to place the jth item in the backpack, and regarding the state array elements
Figure 54871DEST_PATH_IMAGE027
In other words, the new state is
Figure 209909DEST_PATH_IMAGE028
When is coming into contact with
Figure 479217DEST_PATH_IMAGE029
When the item j is selected to be put into the backpack, otherwise, the item j is not selected to be put into the backpack, and the j-th row state array F [ j ] is filled in sequence];
Last element of slave state array
Figure 327087DEST_PATH_IMAGE030
Begin to judge if item j is selected for placement in the backpack, if
Figure 49055DEST_PATH_IMAGE031
Then article
Figure 7784DEST_PATH_IMAGE032
The corresponding item serial number i is recorded into a serial number list X of the loaded backpack, and the remaining state sub-array is
Figure 121145DEST_PATH_IMAGE033
If, if
Figure 139917DEST_PATH_IMAGE034
The remaining state sub-array is
Figure 349181DEST_PATH_IMAGE035
Remaining state subarray
Figure 111601DEST_PATH_IMAGE036
The submatrix is composed of the 1 st row to the ith row and the 1 st column to the jth column of the original state array or the residual state subarray;
for any remaining state subarray, assume it to be
Figure 89921DEST_PATH_IMAGE037
When is coming into contact with
Figure 14015DEST_PATH_IMAGE038
When, when
Figure 710576DEST_PATH_IMAGE039
The item serial number i corresponding to the item j is recorded in the serial number list X of the loaded backpack, and a new remaining state sub-array
Figure 11107DEST_PATH_IMAGE040
If, if
Figure 860245DEST_PATH_IMAGE041
New remaining state subarrays
Figure 955240DEST_PATH_IMAGE042
This step is repeated until the new remaining state subarray is empty.
CN202211140581.XA 2022-09-20 2022-09-20 Method for solving ordered knapsack problem segmentation dynamic programming under limited resources Active CN115221460B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211140581.XA CN115221460B (en) 2022-09-20 2022-09-20 Method for solving ordered knapsack problem segmentation dynamic programming under limited resources

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211140581.XA CN115221460B (en) 2022-09-20 2022-09-20 Method for solving ordered knapsack problem segmentation dynamic programming under limited resources

Publications (2)

Publication Number Publication Date
CN115221460A CN115221460A (en) 2022-10-21
CN115221460B true CN115221460B (en) 2023-01-06

Family

ID=83617509

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211140581.XA Active CN115221460B (en) 2022-09-20 2022-09-20 Method for solving ordered knapsack problem segmentation dynamic programming under limited resources

Country Status (1)

Country Link
CN (1) CN115221460B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103687027A (en) * 2013-12-26 2014-03-26 广东省电信规划设计院有限公司 Resource allocation method and system for LTE (Long Term Evolution) network
CN112214718A (en) * 2020-10-26 2021-01-12 湖南工业大学 Method for solving bounded knapsack problem based on improved dynamic programming algorithm
CN113887122A (en) * 2021-07-30 2022-01-04 南京信息工程大学 Mixed frog leaping solving method for multi-target knapsack problem
CN114691302A (en) * 2022-04-21 2022-07-01 南京大学 Dynamic cache replacement method and device for big data processing

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8555268B2 (en) * 2007-08-17 2013-10-08 National Ict Australia Limited Automating dynamic programs
US8554702B2 (en) * 2010-12-17 2013-10-08 Oracle International Corporation Framework for optimized packing of items into a container
CN109583749B (en) * 2018-11-27 2022-11-08 中国人民解放军海军大连舰艇学院 Software development cost intelligent control method and system based on dynamic programming
CN111507846A (en) * 2020-04-17 2020-08-07 新分享科技服务(深圳)有限公司 Asset screening and packaging method and device, storage medium and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103687027A (en) * 2013-12-26 2014-03-26 广东省电信规划设计院有限公司 Resource allocation method and system for LTE (Long Term Evolution) network
CN112214718A (en) * 2020-10-26 2021-01-12 湖南工业大学 Method for solving bounded knapsack problem based on improved dynamic programming algorithm
CN113887122A (en) * 2021-07-30 2022-01-04 南京信息工程大学 Mixed frog leaping solving method for multi-target knapsack problem
CN114691302A (en) * 2022-04-21 2022-07-01 南京大学 Dynamic cache replacement method and device for big data processing

Non-Patent Citations (8)

* Cited by examiner, † Cited by third party
Title
A dynamic programming algorithm for the Knapsack Problem with Setup;KhalilChebil等;《ELSEVIER》;20150519;全文 *
利用动态规划解决01背包问题;孙宇兴等;《现代交际》;20100515(第05期);全文 *
动态规划法的应用分析;李小莲;《计算机时代》;20190615(第06期);全文 *
基于0/1背包问题的算法探究;张景成等;《电脑知识与技术(学术交流)》;20070608(第11期);全文 *
求解01背包问题的贪婪蛙跳算法;高思齐等;《计算机科学》;20180715(第07期);全文 *
结合关键点概率与路径相似度的多路径覆盖策略;钱忠胜等;《软件学报》;20220215;全文 *
考虑时间因素的0-1背包调度问题;王正理等;《计算机科学》;20180415(第04期);全文 *
背包问题的两阶段动态规划算法;崔耀东等;《高校应用数学学报A辑(中文版)》;19931205(第04期);全文 *

Also Published As

Publication number Publication date
CN115221460A (en) 2022-10-21

Similar Documents

Publication Publication Date Title
JP7245338B2 (en) neural network processor
CN107239829B (en) Method for optimizing artificial neural network
AU692929B2 (en) Priority queue filtering system and method of operation
US20220147928A1 (en) Order processing method, apparatus, device, system, and storage medium
KR102038390B1 (en) Artificial neural network module and scheduling method thereof for highly effective parallel processing
CN104915817A (en) Loading method and apparatus for container
MXPA97002050A (en) Filter system of priority row and metodode operac
CN111027902B (en) Unmanned warehouse goods transportation matching method and device
CN108287666A (en) Date storage method and device for cloud storage environment
CN107729423A (en) A kind of big data processing method and processing device
CN112084037A (en) Memory allocation method and device of neural network
CN113128839B (en) High-end equipment distributed manufacturing and multi-mode transportation oriented cooperative scheduling method
US20170293839A1 (en) Systems and Methods for Multi-Objective Heuristics with Conditional Genes
KR20190111810A (en) Systems and methods of data processing
CN108345419A (en) A kind of generation method and device of information recommendation list
CN115221460B (en) Method for solving ordered knapsack problem segmentation dynamic programming under limited resources
KR20220134035A (en) Processing-in-memory method for convolution operations
CN114143322A (en) Method for evaluating configuration action of computing resources in mixed cloud scene
CN113112084A (en) Training plane rear body research and development flow optimization method and device
CN114912647A (en) Apparatus, method and machine-readable storage medium for decision making
CN113255094A (en) Optimization device, optimization program, and optimization method
US20240140713A1 (en) Information processing device, information processing method, computer program product, and information processing system
TWI788257B (en) Method and non-transitory computer readable medium for compute-in-memory macro arrangement, and electronic device applying the same
CN118034198A (en) Task scheduling method, device, equipment and storage medium
Ye et al. Solving the combined modular product scheduling and production cell reconfiguration problem: a GA approach with parallel chromosome coding

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant