3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-29 11:55:51 +00:00

add cancellations

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

syntax errors

Signed-off-by: Lev Nachmanson <levnach@microsoft.com>

use std::vector instead of vector in cut_solver temporarily

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix in is_upper_bound, is_lower_bound

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add bound() for polynomial, needs more testing

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on resolve

Signed-off-by: Lev Nachmanson <levnach@microsoft.com>

implement resolve()

Signed-off-by: Lev Nachmanson <levnach@microsoft.com>

implement improves()

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

replace low_bound by lower_bound

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

better printing in cut_solver.h

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add value vector to cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on bound propagaion for cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

bound propagation for integer inequalites

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

bound propagation for integer inequalites

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

bound propagattions on integers

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

adding m_explanation field to cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify bound propagation in cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

calculate conflict explanation

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

change m_explanation type to a set

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

making cut_solver a member of int_solver, missing push/pop support

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

Nikolaj's comments

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

Nikolaj's comments

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

return explanations from cut_solver and hook up push/pop

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

hook up push/pop

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

using resize of std::vector

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

it is a big squashed commit

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

rename hpp to cpp

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fixes in push/pop of cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

return simple inequalities a part of a conflict

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on propagation and the main loop

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add file

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

init m_v[j], the var values only when j is fixed

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

handle decide in cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

start on resolve_conflict

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

start on resolve_conflict

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

remove cut_solver_def.h

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

in the middle

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

change signature of resolve

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix the domain of the decided var

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on tightening of ineqs

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on tight ineqs

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on tightening

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on tightening

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

resolve conflict

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix in usage of resolve()

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on conflict resolution

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

cut_solver is not a template

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

represent var_info as a class, not a struct

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

make literal a class

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

better resolve_conflict scheme, and switch to *constraints in literals

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

debug conflict resolution in cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

switch to vector

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

remove nondetermenistic behavior from cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

debug resolve conflict

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix backjump

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix backjump

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix backjump

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix backjump

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

dumb explanation

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

get rid of a parameter

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add lemmas origins

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use lemma_origins to provide correct explanations

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use lemma_origins to provide correct explanations

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

store lemmas in a separate vector

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use std::unordered_set for m_dependent_constraints

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use std::unordered_set for m_dependent_constraints

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix bugs with lemmas

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

finding conflicting cores

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

switch from changed variables to active_set

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

less active constraints

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

work on cut_solver.h

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

propagate simple constraing immediately

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

propagate simple constraints immediately

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fixing bugs with active set

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

remove const_cast

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

towards unbounded variables

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

toward unbounded variables

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

toward unbounded variables

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

make lemmas_origins a set

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use correct hash and equal in m_lemma_origins

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add testing code

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add testing code

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

debug

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

debug unlimited vars

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

take in Nikolaj's comments and improvements

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

address the comments

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

handle unlimited vars in check_inconsistent

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

debug

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

detect trivial polynomials in resolve

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

Nikolaj's changes

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify handling of m_global_bound_var

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

decide on m_global_bound_var if it is not fixed

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify m_global_bound_var

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

remove m_global_bound_var, simplify the indexing of var_infos of cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

do not run cut_solver with vars without any bound

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

small changes

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add cancellation in cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

do not pop lemmas during a cut_solver run

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

treating cut_solver as an heurisitic

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

prepare for cut_solver returning undef

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify work with active_set in cut_solver, add stats

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify var_info literals

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix a bug in fill_conflict_explanation

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix a bug in the conflict explanation

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add timeout to validate_* in theory_lra.cpp

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify cut_solver, no special treatment for simple constraints

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

cleanup the cancel story

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

cleanup cancelling

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix a bug in push/pop of cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

extract a method in int_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

some progress with the new scheme

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

add testing code

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fixes in test and in literal creation

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix a bug in bound propagation in cut_solver.h

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

simplify cut_solver

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

provide valid conflict explanation

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use a lazy push in stacked_map

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use a lazy push in stacked_map

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

optimize stack operations on var_info's domains

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fix a bug in tightening

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

use the standard tactics from qflia_tactic

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

spread the var domain stack over literals

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

spread the var domain stack over literals

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

avoid cycling in cut_solver.h and fixes in push/pop

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>

fixes after rebase

Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
This commit is contained in:
Lev Nachmanson 2017-10-03 11:50:21 -07:00
parent 58ca4518e5
commit 6202b2f2e4
103 changed files with 7035 additions and 5106 deletions

View file

@ -1,377 +0,0 @@
/*++
Copyright (c) 2017 Microsoft Corporation
Module Name:
<name>
Abstract:
<abstract>
Author:
Lev Nachmanson (levnach)
Revision History:
--*/
#include "util/lp/lp_dual_simplex.h"
namespace lp{
template <typename T, typename X> void lp_dual_simplex<T, X>::decide_on_status_after_stage1() {
switch (m_core_solver->get_status()) {
case lp_status::OPTIMAL:
if (this->m_settings.abs_val_is_smaller_than_artificial_tolerance(m_core_solver->get_cost())) {
this->m_status = lp_status::FEASIBLE;
} else {
this->m_status = lp_status::UNBOUNDED;
}
break;
case lp_status::DUAL_UNBOUNDED:
lp_unreachable();
case lp_status::ITERATIONS_EXHAUSTED:
this->m_status = lp_status::ITERATIONS_EXHAUSTED;
break;
case lp_status::TIME_EXHAUSTED:
this->m_status = lp_status::TIME_EXHAUSTED;
break;
case lp_status::FLOATING_POINT_ERROR:
this->m_status = lp_status::FLOATING_POINT_ERROR;
break;
default:
lp_unreachable();
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fix_logical_for_stage2(unsigned j) {
lp_assert(j >= this->number_of_core_structurals());
switch (m_column_types_of_logicals[j - this->number_of_core_structurals()]) {
case column_type::low_bound:
m_low_bounds[j] = numeric_traits<T>::zero();
m_column_types_of_core_solver[j] = column_type::low_bound;
m_can_enter_basis[j] = true;
break;
case column_type::fixed:
this->m_upper_bounds[j] = m_low_bounds[j] = numeric_traits<T>::zero();
m_column_types_of_core_solver[j] = column_type::fixed;
m_can_enter_basis[j] = false;
break;
default:
lp_unreachable();
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fix_structural_for_stage2(unsigned j) {
column_info<T> * ci = this->m_map_from_var_index_to_column_info[this->m_core_solver_columns_to_external_columns[j]];
switch (ci->get_column_type()) {
case column_type::low_bound:
m_low_bounds[j] = numeric_traits<T>::zero();
m_column_types_of_core_solver[j] = column_type::low_bound;
m_can_enter_basis[j] = true;
break;
case column_type::fixed:
case column_type::upper_bound:
lp_unreachable();
case column_type::boxed:
this->m_upper_bounds[j] = ci->get_adjusted_upper_bound() / this->m_column_scale[j];
m_low_bounds[j] = numeric_traits<T>::zero();
m_column_types_of_core_solver[j] = column_type::boxed;
m_can_enter_basis[j] = true;
break;
case column_type::free_column:
m_can_enter_basis[j] = true;
m_column_types_of_core_solver[j] = column_type::free_column;
break;
default:
lp_unreachable();
}
// T cost_was = this->m_costs[j];
this->set_scaled_cost(j);
}
template <typename T, typename X> void lp_dual_simplex<T, X>::unmark_boxed_and_fixed_columns_and_fix_structural_costs() {
unsigned j = this->m_A->column_count();
while (j-- > this->number_of_core_structurals()) {
fix_logical_for_stage2(j);
}
j = this->number_of_core_structurals();
while (j--) {
fix_structural_for_stage2(j);
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::restore_right_sides() {
unsigned i = this->m_A->row_count();
while (i--) {
this->m_b[i] = m_b_copy[i];
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::solve_for_stage2() {
m_core_solver->restore_non_basis();
m_core_solver->solve_yB(m_core_solver->m_y);
m_core_solver->fill_reduced_costs_from_m_y_by_rows();
m_core_solver->start_with_initial_basis_and_make_it_dual_feasible();
m_core_solver->set_status(lp_status::FEASIBLE);
m_core_solver->solve();
switch (m_core_solver->get_status()) {
case lp_status::OPTIMAL:
this->m_status = lp_status::OPTIMAL;
break;
case lp_status::DUAL_UNBOUNDED:
this->m_status = lp_status::INFEASIBLE;
break;
case lp_status::TIME_EXHAUSTED:
this->m_status = lp_status::TIME_EXHAUSTED;
break;
case lp_status::FLOATING_POINT_ERROR:
this->m_status = lp_status::FLOATING_POINT_ERROR;
break;
default:
lp_unreachable();
}
this->m_second_stage_iterations = m_core_solver->total_iterations();
this->m_total_iterations = (this->m_first_stage_iterations + this->m_second_stage_iterations);
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_x_with_zeros() {
unsigned j = this->m_A->column_count();
while (j--) {
this->m_x[j] = numeric_traits<T>::zero();
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::stage1() {
lp_assert(m_core_solver == nullptr);
this->m_x.resize(this->m_A->column_count(), numeric_traits<T>::zero());
if (this->m_settings.get_message_ostream() != nullptr)
this->print_statistics_on_A(*this->m_settings.get_message_ostream());
m_core_solver = new lp_dual_core_solver<T, X>(
*this->m_A,
m_can_enter_basis,
this->m_b, // the right side vector
this->m_x,
this->m_basis,
this->m_nbasis,
this->m_heading,
this->m_costs,
this->m_column_types_of_core_solver,
this->m_low_bounds,
this->m_upper_bounds,
this->m_settings,
*this);
m_core_solver->fill_reduced_costs_from_m_y_by_rows();
m_core_solver->start_with_initial_basis_and_make_it_dual_feasible();
if (this->m_settings.abs_val_is_smaller_than_artificial_tolerance(m_core_solver->get_cost())) {
// skipping stage 1
m_core_solver->set_status(lp_status::OPTIMAL);
m_core_solver->set_total_iterations(0);
} else {
m_core_solver->solve();
}
decide_on_status_after_stage1();
this->m_first_stage_iterations = m_core_solver->total_iterations();
}
template <typename T, typename X> void lp_dual_simplex<T, X>::stage2() {
unmark_boxed_and_fixed_columns_and_fix_structural_costs();
restore_right_sides();
solve_for_stage2();
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_first_stage_solver_fields() {
unsigned slack_var = this->number_of_core_structurals();
unsigned artificial = this->number_of_core_structurals() + this->m_slacks;
for (unsigned row = 0; row < this->row_count(); row++) {
fill_first_stage_solver_fields_for_row_slack_and_artificial(row, slack_var, artificial);
}
fill_costs_and_bounds_and_column_types_for_the_first_stage_solver();
}
template <typename T, typename X> column_type lp_dual_simplex<T, X>::get_column_type(unsigned j) {
lp_assert(j < this->m_A->column_count());
if (j >= this->number_of_core_structurals()) {
return m_column_types_of_logicals[j - this->number_of_core_structurals()];
}
return this->m_map_from_var_index_to_column_info[this->m_core_solver_columns_to_external_columns[j]]->get_column_type();
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_structural_column(unsigned j) {
// see 4.7 in the dissertation of Achim Koberstein
lp_assert(this->m_core_solver_columns_to_external_columns.find(j) !=
this->m_core_solver_columns_to_external_columns.end());
T free_bound = T(1e4); // see 4.8
unsigned jj = this->m_core_solver_columns_to_external_columns[j];
lp_assert(this->m_map_from_var_index_to_column_info.find(jj) != this->m_map_from_var_index_to_column_info.end());
column_info<T> * ci = this->m_map_from_var_index_to_column_info[jj];
switch (ci->get_column_type()) {
case column_type::upper_bound: {
std::stringstream s;
s << "unexpected bound type " << j << " "
<< column_type_to_string(get_column_type(j));
throw_exception(s.str());
break;
}
case column_type::low_bound: {
m_can_enter_basis[j] = true;
this->set_scaled_cost(j);
this->m_low_bounds[j] = numeric_traits<T>::zero();
this->m_upper_bounds[j] =numeric_traits<T>::one();
break;
}
case column_type::free_column: {
m_can_enter_basis[j] = true;
this->set_scaled_cost(j);
this->m_upper_bounds[j] = free_bound;
this->m_low_bounds[j] = -free_bound;
break;
}
case column_type::boxed:
m_can_enter_basis[j] = false;
this->m_costs[j] = numeric_traits<T>::zero();
this->m_upper_bounds[j] = this->m_low_bounds[j] = numeric_traits<T>::zero(); // is it needed?
break;
default:
lp_unreachable();
}
m_column_types_of_core_solver[j] = column_type::boxed;
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_logical_column(unsigned j) {
this->m_costs[j] = 0;
lp_assert(get_column_type(j) != column_type::upper_bound);
if ((m_can_enter_basis[j] = (get_column_type(j) == column_type::low_bound))) {
m_column_types_of_core_solver[j] = column_type::boxed;
this->m_low_bounds[j] = numeric_traits<T>::zero();
this->m_upper_bounds[j] = numeric_traits<T>::one();
} else {
m_column_types_of_core_solver[j] = column_type::fixed;
this->m_low_bounds[j] = numeric_traits<T>::zero();
this->m_upper_bounds[j] = numeric_traits<T>::zero();
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_costs_and_bounds_and_column_types_for_the_first_stage_solver() {
unsigned j = this->m_A->column_count();
while (j-- > this->number_of_core_structurals()) { // go over logicals here
fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_logical_column(j);
}
j = this->number_of_core_structurals();
while (j--) {
fill_costs_bounds_types_and_can_enter_basis_for_the_first_stage_solver_structural_column(j);
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::fill_first_stage_solver_fields_for_row_slack_and_artificial(unsigned row,
unsigned & slack_var,
unsigned & artificial) {
lp_assert(row < this->row_count());
auto & constraint = this->m_constraints[this->m_core_solver_rows_to_external_rows[row]];
// we need to bring the program to the form Ax = b
T rs = this->m_b[row];
switch (constraint.m_relation) {
case Equal: // no slack variable here
set_type_for_logical(artificial, column_type::fixed);
this->m_basis[row] = artificial;
this->m_costs[artificial] = numeric_traits<T>::zero();
(*this->m_A)(row, artificial) = numeric_traits<T>::one();
artificial++;
break;
case Greater_or_equal:
set_type_for_logical(slack_var, column_type::low_bound);
(*this->m_A)(row, slack_var) = - numeric_traits<T>::one();
if (rs > 0) {
// adding one artificial
set_type_for_logical(artificial, column_type::fixed);
(*this->m_A)(row, artificial) = numeric_traits<T>::one();
this->m_basis[row] = artificial;
this->m_costs[artificial] = numeric_traits<T>::zero();
artificial++;
} else {
// we can put a slack_var into the basis, and avoid adding an artificial variable
this->m_basis[row] = slack_var;
this->m_costs[slack_var] = numeric_traits<T>::zero();
}
slack_var++;
break;
case Less_or_equal:
// introduce a non-negative slack variable
set_type_for_logical(slack_var, column_type::low_bound);
(*this->m_A)(row, slack_var) = numeric_traits<T>::one();
if (rs < 0) {
// adding one artificial
set_type_for_logical(artificial, column_type::fixed);
(*this->m_A)(row, artificial) = - numeric_traits<T>::one();
this->m_basis[row] = artificial;
this->m_costs[artificial] = numeric_traits<T>::zero();
artificial++;
} else {
// we can put slack_var into the basis, and avoid adding an artificial variable
this->m_basis[row] = slack_var;
this->m_costs[slack_var] = numeric_traits<T>::zero();
}
slack_var++;
break;
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::augment_matrix_A_and_fill_x_and_allocate_some_fields() {
this->count_slacks_and_artificials();
this->m_A->add_columns_at_the_end(this->m_slacks + this->m_artificials);
unsigned n = this->m_A->column_count();
this->m_column_types_of_core_solver.resize(n);
m_column_types_of_logicals.resize(this->m_slacks + this->m_artificials);
this->m_costs.resize(n);
this->m_upper_bounds.resize(n);
this->m_low_bounds.resize(n);
m_can_enter_basis.resize(n);
this->m_basis.resize(this->m_A->row_count());
}
template <typename T, typename X> void lp_dual_simplex<T, X>::copy_m_b_aside_and_set_it_to_zeros() {
for (unsigned i = 0; i < this->m_b.size(); i++) {
m_b_copy.push_back(this->m_b[i]);
this->m_b[i] = numeric_traits<T>::zero(); // preparing for the first stage
}
}
template <typename T, typename X> void lp_dual_simplex<T, X>::find_maximal_solution(){
if (this->problem_is_empty()) {
this->m_status = lp_status::EMPTY;
return;
}
this->flip_costs(); // do it for now, todo ( remove the flipping)
this->cleanup();
if (this->m_status == lp_status::INFEASIBLE) {
return;
}
this->fill_matrix_A_and_init_right_side();
this->fill_m_b();
this->scale();
augment_matrix_A_and_fill_x_and_allocate_some_fields();
fill_first_stage_solver_fields();
copy_m_b_aside_and_set_it_to_zeros();
stage1();
if (this->m_status == lp_status::FEASIBLE) {
stage2();
}
}
template <typename T, typename X> T lp_dual_simplex<T, X>::get_current_cost() const {
T ret = numeric_traits<T>::zero();
for (auto it : this->m_map_from_var_index_to_column_info) {
ret += this->get_column_cost_value(it.first, it.second);
}
return -ret; // we flip costs for now
}
}