Stay organized with collections
Save and categorize content based on your preferences.
C++ Reference: class BaseLns
Note: This documentation is automatically generated.
This is the base class for building an Lns operator. An Lns fragment is a
collection of variables which will be relaxed. Fragments are built with
NextFragment(), which returns false if there are no more fragments to build.
Optionally one can override InitFragments, which is called from
LocalSearchOperator::Start to initialize fragment data.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-06 UTC."],[[["\u003cp\u003e\u003ccode\u003eBaseLns\u003c/code\u003e is the foundation for creating Large Neighborhood Search (LNS) operators in constraint programming, used to define relaxations of problem variables.\u003c/p\u003e\n"],["\u003cp\u003eLNS fragments represent collections of variables to be relaxed, and are created iteratively using the \u003ccode\u003eNextFragment()\u003c/code\u003e method, which returns \u003ccode\u003efalse\u003c/code\u003e when all fragments have been generated.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eInitFragments()\u003c/code\u003e method is available to initialize data for fragments, and is automatically called at the beginning of the search.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code example demonstrates a simple LNS implementation (\u003ccode\u003eOneVarLns\u003c/code\u003e) that relaxes one variable at a time.\u003c/p\u003e\n"]]],["`BaseLns` is a base class for building Lns operators, which relax collections of variables called fragments. `NextFragment()` builds these fragments, returning false when none remain. `InitFragments()` initializes fragment data, called at the start of local search. `AppendToFragment()` adds a variable to the current fragment. `BaseLns` constructor, `~BaseLns` destructor, `FragmentSize()`, and `HasFragments()` are also part of this class. The provided example demonstrates a `OneVarLns` subclass, which relaxes one variable at a time.\n"],null,["# BaseLns\n\nC++ Reference: class BaseLns\n============================\n\n\nNote: This documentation is automatically generated.\nThis is the base class for building an Lns operator. An Lns fragment is a collection of variables which will be relaxed. Fragments are built with NextFragment(), which returns false if there are no more fragments to build. Optionally one can override InitFragments, which is called from LocalSearchOperator::Start to initialize fragment data. \n\nHere's a sample relaxing one variable at a time: \n\n```\nclass OneVarLns : public BaseLns {\n public:\n OneVarLns(const std::vector\u003cIntVar*\u003e& vars) : BaseLns(vars), index_(0) {}\n virtual ~OneVarLns() {}\n virtual void InitFragments() { index_ = 0; }\n virtual bool NextFragment() {\n const int size = Size();\n if (index_ \u003c size) {\n AppendToFragment(index_);\n ++index_;\n return true;\n } else {\n return false;\n }\n }\n\n\n\n private:\n int index_;\n };\n```\n\n| Method ||\n|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|\n| [`AppendToFragment`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1266) | Return type: `void ` Arguments: `int index` \u003cbr /\u003e |\n| [`BaseLns`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1262) | Return type: `explicit ` Arguments: `const std::vector\u003cIntVar*\u003e& vars` \u003cbr /\u003e |\n| [`~BaseLns`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1263) | \u003cbr /\u003e |\n| [`FragmentSize`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1267) | Return type: `int ` \u003cbr /\u003e |\n| [`HasFragments`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1268) | Return type: `bool ` \u003cbr /\u003e |\n| [`InitFragments`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1264) | Return type: `virtual void ` \u003cbr /\u003e |\n| [`NextFragment`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/constraint_solveri.h#L1265) | Return type: `virtual bool ` \u003cbr /\u003e |"]]