<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Avijit Basak on Medium]]></title>
        <description><![CDATA[Stories by Avijit Basak on Medium]]></description>
        <link>https://medium.com/@avijitbasak?source=rss-db9b19464f23------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*G6RW7_NI3yPQbAH0</url>
            <title>Stories by Avijit Basak on Medium</title>
            <link>https://medium.com/@avijitbasak?source=rss-db9b19464f23------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 20:00:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@avijitbasak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rank-Based Adaptive Mutation: An Intuitive Explanation]]></title>
            <link>https://medium.com/the-modern-scientist/rank-based-adaptive-mutation-an-intuitive-explanation-f2deef10950f?source=rss-db9b19464f23------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2deef10950f</guid>
            <category><![CDATA[mutation]]></category>
            <category><![CDATA[genetic-algorithm]]></category>
            <category><![CDATA[convergence]]></category>
            <category><![CDATA[adaptive]]></category>
            <category><![CDATA[adaptive-mutation]]></category>
            <dc:creator><![CDATA[Avijit Basak]]></dc:creator>
            <pubDate>Wed, 14 Jan 2026 08:05:03 GMT</pubDate>
            <atom:updated>2026-01-14T08:05:03.567Z</atom:updated>
            <content:encoded><![CDATA[<p>Genetic Algorithms (GAs) have become most useful algorithm for optimization in engineering, machine learning, and operations research. GA was initially proposed by John Holland inspired by natural evolution. The algorithm uses fitness-based selection, crossover, and <strong>mutation</strong> — to evolve solutions toward optimality. But while most implementations stick with fixed probabilities for crossover and mutation operators, adaptive probabilities have emerged as an alternative to improve performance. A rank based adaptive mutation approach is explained here intuitively with comparison as an alternative to the fitness-based approach.</p><p><strong>An Intuition for Adaptive Approach for Mutation</strong></p><p>A fixed mutation probability must remain very low as this usually alters the best chromosomes hence affects the convergence process. Adaptive mutation probability was proposed as an alternative approach to mitigate the risk. In fitness based adaptive mutation strategies, the probability of mutation for an individual chromosome is usually calculated based on its fitness relative to the best in the population:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*b7QyiPATadXct5_PIU95aA.png" /></figure><p>However, the drawback to the mentioned approach is when many chromosomes have similar fitness values close to the best, the mutation probabilities collapse toward zero for most of the population. To explain the scenario, imagine a hypothetical school of mathematics. Students are trained there to improve their skills in mathematics. The objective of the school is to improve the average score of their students as well as top score. The school takes periodic tests to evaluate the students and train them based on their performance. Students who have low scores are given more training and are assigned more tasks than students who have higher scores. This training can be considered analogous to mutation in Genetic algorithm. Assume students are evaluated in exam using percentile which represents the fitness. The reason for choosing percentile is that it is analogous to fitness in GA where the maximum possible fitness (i.e. Global optima) is unknown. The students who earned low percentile in a class test would be assigned more tasks for improvement. Below are the formulae for candidate percentile calculation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*Nfr8u10JBag5AKCCu_nQ4A.png" /></figure><p>This approach <em>seems</em> reasonable — poorly performing students i.e. having lower percentile would receive more assignments as part of training which is analogous to higher mutation probability based on fitness score. However, it suffers from a critical flaw. It depends on the highest mark and number of people who obtained lower marks compared to a specific candidate. Even if the highest mark is just 50% of the total mark it would be computed as a highest (99.99) percentile. There could be considerable number of students obtaining same marks i.e. same percentile. And if the highest mark is low, it is highly probable that lots of students will obtain scores very close to the highest score. In this situation the percentile distribution is mostly skewed. If the students are trained based on their percentile score, they might have received less training than required which is analogous to having lower mutation probability in Genetic algorithm eventually reducing the exploration pressure and resulting in premature convergence.</p><p><strong>The Rank Based Approach as a Remedy</strong></p><p>Let us design a new hypothetical ranking approach based on their percentile to overcome this. Each student would be assigned a rank where a single rank can be assigned to only a single student. Assuming total N students, the student having the maximum percentile would be assigned the highest rank i.e. N. The student who earned the lowest percentile would be assigned lowest rank i.e. 1. Rest of the students would be assigned ranks based on their earned percentile in a monotonically decreasing order. Students having same score would be assigned distinct ranks. Since this approach uses separate ranks for individuals even with same percentile it would ensure students are provided better level of trainings even after having good percentile. This would minimize the chances of converging the marks to local optima. Similarly in Genetic algorithm, since mutation probability now depends only on rank position and not on absolute fitness values, the algorithm preserves exploration pressure even when the population becomes clustered around sub-optimal solutions. The proposed formula for probability calculation is given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*09dZezP_9HtKlQB8ThUzcQ.png" /></figure><p>The worst ranked individual receives the highest probability of mutation, and this probability decreases linearly as rank improves, reaching near zero for the best individual. This approach ensures proper sustenance of mutation probability and good exploration pressure throughout the convergence process. This also ensures population does not converge with local optima.</p><p><strong>References:</strong></p><p><a href="https://arxiv.org/pdf/2104.08842">A Rank based Adaptive Mutation in Genetic Algorithm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2deef10950f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-modern-scientist/rank-based-adaptive-mutation-an-intuitive-explanation-f2deef10950f">Rank-Based Adaptive Mutation: An Intuitive Explanation</a> was originally published in <a href="https://medium.com/the-modern-scientist">The Modern Scientist</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neighborhood Search using Java based optim4j library]]></title>
            <link>https://medium.com/the-modern-scientist/neighborhood-search-using-java-based-optim4j-library-24c17fbc4b97?source=rss-db9b19464f23------2</link>
            <guid isPermaLink="false">https://medium.com/p/24c17fbc4b97</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[large-neighborhood-search]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[aln]]></category>
            <category><![CDATA[combinatorial]]></category>
            <dc:creator><![CDATA[Avijit Basak]]></dc:creator>
            <pubDate>Mon, 30 Dec 2024 08:08:07 GMT</pubDate>
            <atom:updated>2024-12-30T08:08:07.852Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Neighborhood search techniques are meta-heuristic methods which are used to solve combinatorial optimization problems. The optim4j library is a powerful Java-based library designed for implementing optimization algorithms. This blog delves into the basics of neighborhood search algorithms like LNS and ALNS and usage of optim4j for implementing those in java. It provides valuable insights for developers and researchers interested in optimization techniques. The current library version (1.0.2) includes algorithms such as Large Neighborhood Search (LNS) and Adaptive Large Neighborhood Search (ALNS), which are pivotal in solving complex optimization problems.</p><h3>Large Neighborhood Search (LNS)</h3><p>Large Neighborhood Search is a variant of Neighborhood Search algorithm that starts with an initial solution and iteratively searches its neighborhood to find an optimal solution. The algorithm employs a destroy and repair heuristic to explore the domain. The size of neighborhood is considered large to overcome local optima and ensure good optimization quality. The iteration continues until the convergence condition is met.</p><p>The general workflow of the LNS algorithm is as follows:</p><p>1. <strong>Initialization</strong>: Generate an initial solution agent <em>a_current</em> from the problem domain and assign the same as <em>a_best</em>.</p><p>2. <strong>Iteration</strong>: Repeat until the stopping criteria are met:</p><p>2.1. <strong>Destroy</strong>: Partially destroy the current solution <em>a_current</em>.</p><p>2.2. <strong>Repair</strong>: Reconstruct the partially destroyed solution using repair criterion to find a neighbor <em>a_neighbor</em>.</p><p>2.3. <strong>Acceptance</strong>: Decide whether to accept <em>a_neighbor</em> based on a predefined acceptance criterion.</p><p>2.4. <strong>Update</strong>:</p><p>2.4.1. If <em>a_neighbor</em> is acceptable then assign <em>a_neighbor</em> as <em>a_current</em>.</p><p>2.4.2. If <em>a_neighbor</em> is better <em>a_best</em> then assign <em>a_neighbor</em> as <em>a_best</em>.</p><p>3. <strong>Termination</strong>: Return the best solution found <em>a_best</em> once the completion condition is met.</p><h3>Adaptive Large Neighborhood Search (ALNS)</h3><p>Adaptive Large Neighborhood Search extends LNS by utilizing multiple destroy and repair heuristics. The selection of those heuristics is done based on their past performance during optimization. Each heuristic is assigned a score based on their performance in each iteration. The score boundaries are updated periodically for each heuristic based on predefined update period. The destroy and repair heuristics are chosen using roulette wheel selection based on their score boundaries in each iteration. This adaptive approach enhances the algorithm’s ability to find optimal solutions in diverse problem domains of combinatorial optimization.</p><p>The general workflow of the <strong><em>ALNS</em></strong> algorithm is as follows:</p><p>1. <strong>Initialization</strong>: Generate an initial solution <em>a_current</em> from the problem domain I and assign the same as <em>a_best</em>.</p><p>2. <strong>Iteration</strong>: Repeat until the stopping criteria are met:</p><p>2.1. <strong>Choice of Destroyer and Repairer:</strong> Choose repairer and destroyer based on the calculated probabilities of selection.</p><p>2.2. <strong>Destroy</strong>: Partially destruct the current solution <em>a_current</em>.</p><p>2.3. <strong>Repair</strong>: Reconstruct the partially destroyed solution to find a neighbor <em>a_neighbor</em>.</p><p>2.4. <strong>Acceptance</strong>: Decide whether to accept <em>a_neighbor</em> based on a predefined acceptance criterion.</p><p>2.5. <strong>Update</strong>:</p><p>2.5.1. If <em>a_neighbor</em> is accepted, update <em>a_current</em>.</p><p>2.5.2. If <em>a_neighbor</em> is better than <em>a_best</em>, update <em>a_best</em>.</p><p>2.5.3. Update <em>scores</em> for the selected repairer and destroyer based on their performance in current iteration.</p><p>2.5.4. Update <em>score boundaries </em>for each repairer and destroyer periodically based on their accumulated scores of previous iterations.</p><p>3.<strong> Termination</strong>: Return the best solution found <em>a_best</em> once the completion condition is met.</p><h3>Benefits of optim4j</h3><p>The optim4j library provides a robust and extensible java-based solution for implementing neighborhood search algorithms. It offers modular components for defining problem domains, heuristics, and search strategies. Its extensibility feature allows developers to tailor the library to specific optimization problems. The specific components of the library are provided below:</p><p><strong>· Acceptance Criteria:</strong> The library provides few in-built acceptance criteria as well as provides options to define their own criteria. The <em>AcceptanceCriteria</em> interface provides an abstraction for all criteria. The out-of-box criteria are listed below:</p><p>1. Greedy Acceptance: The class <em>GreedyAcceptanceCriteria</em> implements this criterion. It accepts the neighbor agent if it is better than current one.</p><p>2. Threshold Based Acceptance: This criterion is implemented by <em>ThresholdAcceptanceCriteria</em> class. It accepts the neighbor agent if it has better fitness than the current agent or the fitness difference is lesser than or equal to threshold. The threshold is also reduced monotonically by predefined reduction factor in each iteration.</p><p>3. Random Walk Acceptance: The class <em>RandomWalkAcceptanceCriteria</em> implements this criterion. It decides the acceptance of neighbor agent randomly irrespective of its fitness.</p><p>4. Simulated Annealing Acceptance: This criterion is implemented by <em>SimulatedAnnealingAcceptanceCriteria</em> class. It is based on annealing process of metallurgy. It initializes two parameters temperature and decay rate. Temperature is initialized to a high value and the decay rate is set between 0–1. The mathematical function used to estimate the acceptance probability is known as sigmoid as provided below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*eVE7_hgwwc12Jztk43FwYQ.png" /><figcaption>Sigmoid Function</figcaption></figure><p>5.<strong> </strong>Old Bachelor Acceptance: This criterion is implemented by <em>OldBachelorAcceptanceCriteria</em> class. It is used to remove the monotonicity of any acceptance criterion. The library provides an implementation of old bachelor version for threshold-based acceptance. It introduces increment factor along with reduction factor. In case the fitness of neighbor agent is better than current one by threshold value i.e., the neighbor is acceptable, the threshold value would be reduced by reduction factor. Otherwise, the threshold value would be incremented by increment factor.</p><p>6. Custom Acceptance Criterion: Developers can also implement new acceptance criterion by implementing the provided abstraction i.e., <em>AcceptanceCriteria</em> interface.</p><p><strong>· Completion condition:</strong> A handful of completion condition are provided as part of the library to be used by developers as described below:</p><p>1. Fixed Iteration Completion: The algorithm should execute for a fixed number of iterations and provide the best result as solution.</p><p>2. Unchanged Best Fitness Condition: This condition ensures the algorithm should continue to execute until the best solution remains unchanged for a predefined number of iterations.</p><p><strong>· Observer</strong>: A log-based observer <em>OptimizationLogger</em> is provided as part of this library to monitor the optimization process in detail and log the same.</p><p><strong>· Destroyer:</strong> The library provides an interface <em>Destroyer</em> for solution agent destroyer which developers need to implement for their problem domain. Developers need to provide one or more destroyer instances. The destroyer should be able to partially destroy the current solution to create a partially destroyed solution agent.</p><p><strong>· Repairer:</strong> The library provides an interface <em>Repairer</em> for solution agent repairer which developers need to implement for their problem domain. Developers need to provide one or more repairer instances. The repairer should be able to repair the partially destroyed solution to construct a valid solution.</p><p><strong>· Large Neighborhood Search Optimizer:</strong> The LargeNeighborhoodSearchOptimizer class provides an implementation of LNS optimizer. The implementation accepts an initial solution agent, acceptance criterion, completion condition, repairer, destroyer, and an observer. The optimization process transforms the initial solution agent using destroy and repair heuristic over multiple iterations. The new solution in each iteration is accepted based on provided acceptance criteria. The process continues until the completion condition is satisfied. The steps of implementing LNS are described below following library documentation:</p><p>1. <em>Initialize</em> an <strong>acceptance criterion</strong>.</p><pre>AcceptanceCriteria acceptanceCriteria = new SimulatedAnnealingAcceptanceCriteria(100000, .9);</pre><p>2.<strong> </strong>Initialize the <strong>completion condition</strong> based on<strong> fixed iteration</strong>.</p><pre>CompletionCondition completionCondition = new FixedIteration(100);</pre><p>3. <em>Create</em> an initial<strong> solution </strong>agent.</p><pre>public class SolutionAgent implements Agent {<br>  public double evaluate() {<br>  //return the evaluated fitness of this solution.<br>  }<br>};<br>public class PartiallyDestroyedSolutionAgent {<br>  // This class represents the partially destroyed solution agent.<br>}</pre><p>4. <em>Create</em> a <strong>destroyer</strong> to create a partially destroyed solution out of a complete valid solution for the respective problem domain.</p><pre>Destroyer&lt;SolutionAgent, PartiallyDestroyedSolutionAgent&gt; destroyer = new Destroyer&lt;&gt;() {<br>  public PartiallyDestroyedSolutionAgent destroy(SolutionAgent agent) {<br>    // destroy the current agent.<br>  }<br>};</pre><p>5. <em>Create</em> a <strong>repairer</strong> to recreate a complete solution from the partially destroyed solution.</p><pre>Repairer&lt;PartiallyDestroyedSolutionAgent, SolutionAgent&gt; repairer = new Repairer&lt;&gt;() {<br>  public SolutionAgent repairer(PartiallyDestroyedSolutionAgent partiallyDestroyedSolutionAgent) {<br>    // Repair the partially destroyed agent.<br>  }<br>};</pre><p>6. <em>Create</em> an instance of <strong>large neighborhood search</strong> optimizer using the initialization parameters and invoke the optimize method with initial solution.</p><pre>LargeNeighborhoodSearchOptimizer&lt;SolutionAgent, PartiallyDestroyedSolutionAgent&gt; optimizer = <br> new LargeNeighborhoodSearchOptimizer&lt;&gt;(acceptanceCriteria, stoppingCondition, repairer, destroyer, observer);<br>Agent finalSolution = optimizer.optimize(initialSolutionAgent);</pre><p><strong>· Adaptive Large Neighborhood Search:</strong> The <em>AdaptiveLargeNeighborhoodSearchOptimizer</em> class provides an implementation of ALNS algorithm. It accepts an initial solution agent, acceptance criterion, completion condition, repairers, destroyers, and an observer. Alternate constructors also provide options to customize repairer/destroyer scores, score boundary update interval and score reset period. Score reset period has been introduced here to avoid monopoly of any individual repairer or destroyer. Like LNS the optimization process transforms the initial solution to final solution. This class provides a default implementation of repairer destroyer manager along with default initial scores for repairers and destroyers, default update period and score reset period. The default score increments for different acceptance scenarios are also provided. It also provides scopes for providing custom implementation for repairer destroyer manager by implementing the interface <em>RepairerDestroyerManager</em>. Users can also provide custom scores for repairers, destroyers for all acceptance scenarios, as well as score update and reset period using alternate constructor.</p><p>1. <em>Initialize</em> an <strong>acceptance criterion</strong>.</p><pre>AcceptanceCriteria acceptanceCriteria = new SimulatedAnnealingAcceptanceCriteria(100000, .9);</pre><p>2. <em>Initialize</em> the <strong>completion condition</strong> based on<strong> fixed iteration</strong>.</p><pre>CompletionCondition completionCondition = new FixedIteration(100);</pre><p>3. <em>Create</em> an <strong>initial solution agent</strong>.</p><pre>public class SolutionAgent implements Agent {<br>  public double evaluate() {<br>    //return the evaluated fitness of this solution.<br>  }<br>};<br>class PartiallyDestroyedSolutionAgent {<br>  // This class represents the partially destroyed solution agent.<br>}</pre><p>4. <em>Create</em> d<strong>estroyers</strong> to create a partially destroyed solution out of a complete valid solution for the respective problem domain.</p><pre>List&lt;Destroyer&gt; destroyers = new ArrayList&lt;&gt;();<br>Destroyer&lt;SolutionAgent, PartiallyDestroyedSolutionAgent&gt; destroyer = new Destroyer&lt;&gt;() {<br>  public PartiallyDestroyedSolutionAgent destroy(SolutionAgent agent) {<br>    // destroy the current agent.<br>  }<br>};<br>destroyers.add(destroyer);<br>// initialize few more destroyers and add them to list.</pre><p>5. <em>Create</em> <strong>repairers </strong>to create a partially destroyed solution out of a complete valid solution for the respective problem domain.</p><pre><br>List&lt;Repairer&gt; repairers = new ArrayList&lt;&gt;();<br>Repairer&lt;PartiallyDestroyedSolutionAgent, SolutionAgent&gt; repairer = new Repairer&lt;&gt;() {<br>  public SolutionAgent repairer(PartiallyDestroyedSolutionAgent partiallyDestroyedSolutionAgent) {<br>    // Repair the partially destroyed agent.<br>  }<br>};<br>repairers.add(repairer);<br>// initialize few more repairers.</pre><p>6. <em>Create</em> an instance of <strong>large neighborhood search</strong> optimizer using the initialization parameters and invoke the optimize method with initial solution.</p><pre>AdaptiveLargeNeighborhoodSearchOptimizer&lt; SolutionAgent, PartiallyDestroyedSolutionAgent &gt; optimizer<br> = new AdaptiveLargeNeighborhoodSearchOptimizer&lt;&gt;(acceptanceCriteria, completionCondition, repairers, destroyers, observer);<br>Agent finalSolution = optimizer.optimize(initialSolutionAgent);</pre><h3>Maven Dependency</h3><p>Developers need to import the following maven dependency to import the library as part of their java application.</p><pre>&lt;dependency&gt;<br>  &lt;groupId&gt;io.github.avopsoft&lt;/groupId&gt;<br>  &lt;artifactId&gt;optim4j-ns&lt;/artifactId&gt;<br>  &lt;version&gt;1.0.2&lt;/version&gt;<br>&lt;/dependency&gt;</pre><h3>Conclusion</h3><p>The <strong>optim4j</strong> library is a robust and versatile tool for implementing optimization algorithms in Java. Current library version provides implementations for neighborhood search algorithms i.e., large neighborhood search and adaptive large neighborhood search. By providing implementations of both, the library equips developers with the necessary tools to solve complex optimization problems efficiently. The area of application covers different combinatorial optimization problems like <strong>TSP, scheduling, capacitated vehicle routing problem</strong> etc. In this blog I have tried to provide a comprehensive description of the library and its utility to solve those problems. Code samples are also provided for the benefit of developers. Further documentation can be found at the library <a href="https://github.com/avopsoft/optim4j">repository</a>.</p><h3>References:</h3><p>[1] <a href="https://pubsonline.informs.org/doi/10.1287/trsc.1050.0135">An Adaptive Large Neighborhood Search Heuristic for the Pickup and Delivery Problem with Time Windows | Transportation Science</a></p><p>[2] <a href="https://link.springer.com/chapter/10.1007/978-1-4419-1665-5_13">Large Neighborhood Search | SpringerLink</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24c17fbc4b97" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-modern-scientist/neighborhood-search-using-java-based-optim4j-library-24c17fbc4b97">Neighborhood Search using Java based optim4j library</a> was originally published in <a href="https://medium.com/the-modern-scientist">The Modern Scientist</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>