Essential Algorithms A Practical Approach to Computer Algorithms Using Python and C# vol 2 by Unknown

Essential Algorithms A Practical Approach to Computer Algorithms Using Python and C# vol 2 by Unknown

Author:Unknown
Language: eng
Format: epub


// Try to improve the solution.

Boolean: had_improvement = True

While (had_improvement)

Chapter 12 ■ Decision Trees 383

// Assume this time we won't have any improvement.

had_improvement = False

// Try swapping items.

For index = 0 To max_index

<Swap item number index into the other group>

// See if this improves the test solution.

If <this swap improves the test solution> Then

had_improvement = True

Else

<Swap the item back>

End If

Next index

Loop

// See if this solution is an improvement.

<If the test solution is an improvement, save it>

Next i

End MakeImprovements

The algorithm enters a loop to perform a certain number of trials. For each

trial, it picks a random test solution.

It then enters a loop that executes as long as the algorithm finds an improve-

ment for the random test solution. Each time through this improvement loop,

the algorithm tries swapping each item into the group to which it isn’t currently

assigned. If that swap improves the test solution, the algorithm keeps it. If that

swap does not improve the test solution, the algorithm undoes it.

After it can find no more improvements, the algorithm compares the test

solution to the best solution found so far and keeps it if it is better.

You can pick the number of trials to run in the same ways that you can for the

random heuristic described in the previous section. You can let the algorithm

run a fixed number of trials, a number of trials that depends on the number

of weights being partitioned, until it finds no improved best solution, or until

you stop it.

Sometimes, it is not possible to improve a path by making a single swap.

For example, suppose you are partitioning the weights 6, 5, 5, 5, 3, and 3. Sup-

pose also that you pick a random path that makes the two groups {6, 3, 3} and

{5, 5, 5} so that the groups have total weights of 12 and 15. Therefore, their total weights differ by 3.

Moving an item from the first group to the second only makes the difference

greater, so that won’t improve the solution.

If you moved an item with weight 5 from the second group to the first, the

groups would be {6, 5, 3, 3} and {5, 5}, so their total weights would be 17 and

10—also not an improvement.

384

Chapter 12 ■ Decision Trees

No single swap can improve this solution. But if you move an item

with weight 3 from the first group to the second and you also move an

item with weight 5 from the second group to the first, you get the groups {6, 5, 3}

and {5, 5, 3}. The groups would then have weights 14 and 13, an improvement

over the original solution.

The single swap strategy described in this section won’t find this improvement,

because it requires you to make two swaps at the same time. Other improve-

ment strategies try swapping two items at the same time. Of course, there are

also improvements that you cannot make by swapping two items, which you

can make by swapping three items, so that strategy doesn’t always work either.

Still, swapping two items at a time isn’t too difficult and may result in some

improvements, so it is worth implementing.

Simulated



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Eco-friendly approach of bio-indigo synthesis and developing purification methods towards isolation of indigo from indirubin and bacterial fragments by Ramalingam Manivannan & Kaliyan Prabakaran & Young-A Son(234062)
Personalized inhaled bacteriophage therapy for treatment of multidrug-resistant Pseudomonas aeruginosa in cystic fibrosis by unknow(202602)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(102433)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(101966)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(101763)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74562)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50973)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40349)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40271)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40173)
Alkaline-earth metals promote propane dehydrogenation with carbon dioxide through geometric effects: Altering the reaction pathway by unknow(32797)
Induced iron vacancies boosting FeOOH loaded on sustainable Fenton-like collagen fiber membrane for efficient removal of emerging contaminants by unknow(32590)
Efficient electric-field-assisted photochemical conversion of methane to n-propanol exclusively over penetrated TiO2Ti hollow fibers by Guanghui Feng(32510)
Bi2SiO5 nanosheets as piezo-photocatalyst for efficient degradation of 2,4-Dichlorophenol by Hangyu Shi & Yifu Li & Lishan Zhang & Guoguan Liu & Qian Zhang & Xuan Ru & Shan Zhong(32450)
A novel NDIPTA organic heterojunction photocatalyst with built-in electric field for efficient hydrogen production by Jiahui Yang & Baojun Ma & Yongfa Zhu(32422)
Enhanced conversion of methane to liquid-phase oxygenates via hollow ferrite nanotube@horseradish peroxidase based photoenzymatic catalysis by Jun Duan & Shiying Fan & Xinyong Li & Shaomin Liu(32388)
Ordered macroporous superstructure of defective carbon adorned with tiny cobalt sulfide for selective electrocatalytic hydrogenation of cinnamaldehyde by Xiao-Shi Yuan & Sheng-Hua Zhou & San-Mei Wang & Wenbo Wei & Xiaofang Li & Xin-Tao Wu & Qi-Long Zhu(32307)
What's Done in Darkness by Kayla Perrin(27224)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26600)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26522)