Class RandomNeighborhood

  • All Implemented Interfaces:
    INeighbor

    public class RandomNeighborhood
    extends Object
    implements INeighbor
    A Random LNS

    Since:
    18/04/13
    Author:
    Charles Prud'homme
    • Field Detail

      • n

        protected final int n
        Number of variables to consider in this neighbor
      • vars

        protected final IntVar[] vars
        Variables to consider in this neighbor
      • bestSolution

        protected final int[] bestSolution
        Last solution found, wrt vars
      • nbCall

        protected int nbCall
        Number of times this neighbor is called
      • limit

        protected int limit
        Next time the level should be increased
      • level

        protected final int level
        Relaxing factor
      • fragment

        protected BitSet fragment
        Indicate which variables are selected to be part of the fragment
      • mModel

        protected Model mModel
        Reference to the model
    • Constructor Detail

      • RandomNeighborhood

        public RandomNeighborhood​(IntVar[] vars,
                                  int level,
                                  long seed)
        Create a neighbor for LNS which randomly selects variable to be part of a fragment
        Parameters:
        vars - variables to consider in this
        level - relaxing factor
        seed - for randomness
    • Method Detail

      • init

        public void init()
        Description copied from interface: INeighbor
        Initialize this neighbor
        Specified by:
        init in interface INeighbor
      • isSearchComplete

        public boolean isSearchComplete()
        Specified by:
        isSearchComplete in interface INeighbor
        Returns:
        true iff the search is in a complete mode (no fixed variable)
      • recordSolution

        public void recordSolution()
        Description copied from interface: INeighbor
        Record values of decision variables to freeze some ones during the next LNS run
        Specified by:
        recordSolution in interface INeighbor
      • loadFromSolution

        public void loadFromSolution​(Solution solution)
        Description copied from interface: INeighbor
        Load a solution and record it
        Specified by:
        loadFromSolution in interface INeighbor
        Parameters:
        solution - a solution to record
      • fixSomeVariables

        public void fixSomeVariables​(DecisionPath decisionPath)
        Description copied from interface: INeighbor
        Freezes some variables in order to have a fast computation. The fixed variables are declared as decisions in the decision path.
        Specified by:
        fixSomeVariables in interface INeighbor
        Parameters:
        decisionPath - the decision path in which declaring variable to freeze
      • impose

        protected void impose​(int id,
                              DecisionPath decisionPath)
        Impose a decision to be part of the fragment
        Parameters:
        id - variable id in vars
        decisionPath - the current decision path
      • selectVariable

        protected int selectVariable()
        Returns:
        a variable id in vars to be part of the fragment
      • restrictLess

        public void restrictLess()
        Description copied from interface: INeighbor
        Use less restriction at the beginning of a LNS run in order to get better solutions Called when no solution was found during a LNS run (trapped into a local optimum)
        Specified by:
        restrictLess in interface INeighbor