MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / accommodateAlienBasis

Function accommodateAlienBasis

highs/lp_data/HighsSolution.cpp:1914–1973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1912}
1913
1914void accommodateAlienBasis(HighsLpSolverObject& solver_object) {
1915 HighsLp& lp = solver_object.lp_;
1916 HighsBasis& basis = solver_object.basis_;
1917 HighsOptions& options = solver_object.options_;
1918 assert(basis.alien);
1919 HighsInt num_row = lp.num_row_;
1920 HighsInt num_col = lp.num_col_;
1921 assert((int)basis.col_status.size() >= num_col);
1922 assert((int)basis.row_status.size() >= num_row);
1923 std::vector<HighsInt> basic_index;
1924 for (HighsInt iCol = 0; iCol < num_col; iCol++) {
1925 if (basis.col_status[iCol] == HighsBasisStatus::kBasic)
1926 basic_index.push_back(iCol);
1927 }
1928 for (HighsInt iRow = 0; iRow < num_row; iRow++) {
1929 if (basis.row_status[iRow] == HighsBasisStatus::kBasic)
1930 basic_index.push_back(num_col + iRow);
1931 }
1932 HighsInt num_basic_variables = basic_index.size();
1933 HFactor factor;
1934 factor.setupGeneral(&lp.a_matrix_, num_basic_variables, basic_index.data(),
1935 kDefaultPivotThreshold, kDefaultPivotTolerance,
1936 kHighsDebugLevelMin, &options.log_options);
1937 HighsInt rank_deficiency = factor.build();
1938 // Must not have timed out
1939 assert(rank_deficiency >= 0);
1940 // Deduce the basis from basic_index
1941 //
1942 // Set all basic variables to nonbasic
1943 for (HighsInt iCol = 0; iCol < num_col; iCol++) {
1944 if (basis.col_status[iCol] == HighsBasisStatus::kBasic)
1945 basis.col_status[iCol] = HighsBasisStatus::kNonbasic;
1946 }
1947 for (HighsInt iRow = 0; iRow < num_row; iRow++) {
1948 if (basis.row_status[iRow] == HighsBasisStatus::kBasic)
1949 basis.row_status[iRow] = HighsBasisStatus::kNonbasic;
1950 }
1951 // Set at most the first num_row variables in basic_index to basic
1952 const HighsInt use_basic_variables = std::min(num_row, num_basic_variables);
1953 // num_basic_variables is no longer needed, so can be used as a check
1954 num_basic_variables = 0;
1955 for (HighsInt iRow = 0; iRow < use_basic_variables; iRow++) {
1956 HighsInt iVar = basic_index[iRow];
1957 if (iVar < num_col) {
1958 basis.col_status[iVar] = HighsBasisStatus::kBasic;
1959 } else {
1960 basis.row_status[iVar - num_col] = HighsBasisStatus::kBasic;
1961 }
1962 num_basic_variables++;
1963 }
1964 // Complete the assignment of basic variables using the logicals of
1965 // non-pivotal rows
1966 const HighsInt num_missing = num_row - num_basic_variables;
1967 for (HighsInt k = 0; k < num_missing; k++) {
1968 HighsInt iRow = factor.row_with_no_pivot[rank_deficiency + k];
1969 basis.row_status[iRow] = HighsBasisStatus::kBasic;
1970 num_basic_variables++;
1971 }

Callers 1

Calls 5

push_backMethod · 0.80
setupGeneralMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected