The branch boundary method is similar to backtracking, and it is also an algorithm for searching the solution of the problem in the solution space, and the objective is to find a solution satisfying the constraint condition (backtracking is to find all the solutions) or to find the optimal solution in the solution satisfying the condition.
Search Strategy : At the extension node, the husband becomes all of its sons nodes (branches), and then selects the most advantageous node as the next extension node from the current Slipknot point table (based on the value of the function computed for each Slipknot point).
Different ways to select the next extension node from the Slipknot point table result in different branch boundary methods:
1. Queue-type (FIFO) branch boundary method
2, Priority queue-Branch boundary method
Basic idea : Search the solution space Tree of the problem in a way that takes breadth first or takes the least cost (maximum benefit) first.
each Slipknot point has only one chance to become an extension node , and once the Slipknot point becomes an extension node, all its son nodes are generated at once. In these sons ' nodes, the knot of the son causing the non-optimal solution or leading to the Slipknot is discarded, and the remaining son nodes are added to the table of points, repeating the above node expansion process until the desired solution is found.
The branch boundary method consists of two parts: the branch strategy and the "gauge" strategy. The branch strategy is based on the breadth-first strategy of the problem space, and the "gauge" strategy is to use heuristic information pruning strategy to speed up the search speed.
Loading issues
There are two ships and n crates to be shipped, the first ship's load capacity is C1, the second ship's load capacity is C2,wi is the quality of the container, and W1+w2+...+wn <= c1+c2.
Want to determine if there is a way to ship all n containers in full. If so, find out the method.
It is easy to prove that if a given loading problem has a solution, the optimal loading scheme can be obtained by using the following strategy.
(1) First ship as full as possible;
(2) Loading the remaining containers on the second ship
This problem translates into the biggest load problem of the first ship.
IMPORT&NBSP;JAVA.UTIL.*;/*FIFO Branch Search algorithm for solving the optimal solution */public class branchlimitfifosearch { public static void main (String[] args) { int n = 3; / / n boxes float c1 = 50; // load capacity of the first ship float c2 = 50; // Load capacity of the second ship float[] w = { 0, 10, 40, 40 }; // Container Mass Group // Test Examples branchlimitfifoseaRch bfis = new branchlimitfifosearch (n, c1, c2, w); float s = bfis.gets (); // s is the sum of the weights of all containers if (s <= c1 | | &NBSP;S&NBSP;<=&NBSP;C2) { &NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Only need a ship!"); } if (S&NBSP;>&NBSP;C1&NBSP;+&NBSP;C2) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("no solution!"); return; } bfis.maxloading (C1); float bestw = BFIS.GETBESTW (); if (S&NBSP;-&NBSP;BESTW &NBSP;<=&NBSP;C2) { System.out.println ("First ship Load" &NBSP;+&NBSP;BESTW); system.out.println ("Second ship loading " + (S&NBSP;-&NBSP;BESTW)); } else { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("no solution!"); } } private int n; // n boxes private float c1; // load capacity of the first vessel &NBSP;&NBSP;&Nbsp; private float c2; // load capacity of the second ship private float bestw; // maximum loading capacity of the first vessel private float ew = 0; // Current ship loading capacity private float[] w; // Container Mass Group private float s = 0; // The sum of the weights of all containers private myqueue mq = new myqueue (); // fifo Queue //Construction method public branchlimitfifosearch (int _n, float _c1, FLOAT&NBSP;_C2,&NBSP;FLOAT[]&NBSP;_W) { n = _n; c1 = _c1; c2 = _c2; w = _w; for (Float f : _w) { s += f; } } //Optimal Load Value public float maxloading (float c) { mq.put (new float ( -1)); // Initialize node queue, "1" Queued tag layering Layer ew of int i = 1; // e-nodes = 0; // Current ship loading capacity bestw = 0; // currently the mostExcellent value while (!mq.empty ()) { // Search subset Spatial tree if (ew + w[i] <= c) { // check e-node left child, container I can load addlivenode (ew + w[i], i); // container I can load } Addlivenode (ew, i); // right child is always feasible (no need to check), do not load cargo i ew = (Float) mq.get (); // Remove a node if (EW &NBSP;==&NBSP;-1) { // The tail of the arrival layer if (Mq.empty ()) { return bestw; } mq.put (New Float (-1));//Each layer is finished with a "- 1 "Queue to identify" layer " ew = (Float) mq.get (); // Remove a node i++; // ew layer (when the hierarchy is n+1, Search for complete leaf nodes, end of algorithm) } } return bestw; } //add Slipknot Point (WT: Current load, I: Current number of layers) public void addlivenode (float wt, int i) { if (i == n) { // viable leaf junctions if (WT&NBSP;>&NBSP;BESTW) { bestw = wt; //current solution due to current optimal solution, update bestw } } else { // Non-leaf nodes mq.put (new Float (WT)) ; } } &NBSP;&NBSP;PUBLIC&NBSP;INT&NBSP;GETN () { Return n; } public &NBSP;VOID&NBSP;SETN (int n) &NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;THIS.N = n; } public &NBSP;FLOAT&NBSP;GETC1 () { return c1; } public void SetC1 (FLOAT&NBSP;C1) { this.c1 = c1; } public float GetC2 () &NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; return c2; } &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;VOID&NBSP;SETC2 (FLOAT&NBSP;C2) { this.c2 = c2; } &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;FLOAT&NBSP;GETBESTW () { return bestw; } &NBSP;&NBSP;PUBLIC&NBSP;VOID&NBSP;SETBESTW (FLOAT&NBSP;BESTW) { this.bestw = bestw; } public float getew () { return ew; } public void&nbsP;setew (Float ew) { this.ew = Ew; } public float gets () { return s; } public void sets (float s) { this.s = s; } //Custom Queue public class myqueue { private linkedlist list = new linkedlist (); //enqueued public void put (Object o) { list.addlast (o); add new element at the end of the //list } // out Team public object get () { Return list.removefirst (); } Whether the //team is empty public boolean Empty () { return list.isempty (); } } }
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" J_0003.gif "/>
This article is from a "stroll," blog, please be sure to keep this source http://macxiao.blog.51cto.com/9606147/1588900
Branch boundary Method (BFS)