Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproduce gat issue #38

Merged
merged 3 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/max_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
F: SparseElement<F> + Zero + Eq + NonZero,
{
type Column = Column;
type Cost<'a> = Cost;
type Cost<'a> where Self: 'a = Cost;
type Rhs = F;

fn column(&self, j: usize) -> Self::Column {
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ pub trait SolveRelaxation: MatrixProvider {
/// # Return value
///
/// Whether the problem is feasible, and if so, a solution if the problem is bounded.
fn solve_relaxation<IM>(&self) -> OptimizationResult<IM::F>
fn solve_relaxation<'provider, IM>(&'provider self) -> OptimizationResult<IM::F>
where
IM: InverseMaintener<F:
im_ops::FieldHR +
im_ops::Column<<Self::Column as Column>::F> +
im_ops::Cost<ArtificialCost> +
im_ops::Cost<Self::Cost<'provider>> +
im_ops::Rhs<Self::Rhs> +
im_ops::Column<Self::Rhs> +
>,
for<'r> IM::F: im_ops::Cost<Self::Cost<'r>>,
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/two_phase/matrix_provider/column/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait Column: ColumnIntoIterator<Self::F> + Debug {
/// Type of struct to iterate over this column.
///
/// It should be somewhat cheaply cloneable and as such not be too large.
type Iter<'a>: ColumnIterator<'a, F=Self::F>;
type Iter<'a>: ColumnIterator<'a, F=Self::F> where Self: 'a;

/// Derive the iterator object.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ where
MP: MatrixProvider<Column: IntoFilteredColumn>,
{
type Column = <MP::Column as IntoFilteredColumn>::Filtered;
type Cost<'a> = MP::Cost<'a>;
type Cost<'a> where Self: 'a = MP::Cost<'provider>;
type Rhs = MP::Rhs;

fn column(&self, j: usize) -> Self::Column {
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/two_phase/matrix_provider/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait Filtered: MatrixProvider {
/// Derive a variant of the matrix provider that has rows removed from it.
pub trait ToFiltered: MatrixProvider {
/// The resulting matrix provider type.
type Filtered<'provider>: Filtered<Column: Column<F=<Self::Column as Column>::F>>;
type Filtered<'provider>: Filtered<Column: Column<F=<Self::Column as Column>::F>> where Self: 'provider;

/// Derive a variant of the matrix provider that has rows removed from it.
///
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/two_phase/matrix_provider/matrix_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ where
for<'r> &'r F: FieldRef<F>,
{
type Column = Column<F>;
type Cost<'a> = Option<&'a <Self::Column as ColumnTrait>::F>;
type Cost<'a> where Self: 'a = Option<&'a <Self::Column as ColumnTrait>::F>;
type Rhs = F;

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/two_phase/matrix_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait MatrixProvider {
///
/// This type will often be of the form `Option<_>` so to not have to store any zero values, the
/// inner type would never be zero in that case.
type Cost<'a>;
type Cost<'a> where Self: 'a;

/// Right hand side type.
type Rhs: ops::Rhs;
Expand Down
8 changes: 4 additions & 4 deletions src/algorithm/two_phase/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ where
MP: MatrixProvider<Column: Identity + IntoFilteredColumn>,
{
// TODO(ENHANCEMENT): Specialize for MatrixProviders that can be filtered directly.
default fn solve_relaxation<IM>(&self) -> OptimizationResult<IM::F>
default fn solve_relaxation<'provider, IM>(&'provider self) -> OptimizationResult<IM::F>
where
IM: InverseMaintener<F:
im_ops::FieldHR +
im_ops::Column<<<Self as MatrixProvider>::Column as Column>::F> +
im_ops::Cost<ArtificialCost> +
im_ops::Cost<MP::Cost<'provider>> +
im_ops::Rhs<MP::Rhs> +
>,
for<'r> IM::F: im_ops::Cost<MP::Cost<'r>>,
{
match self.compute_bfs_giving_im::<IM>() {
RankedFeasibilityResult::Feasible {
Expand Down Expand Up @@ -84,15 +84,15 @@ where
MP: MatrixProvider<Column: Identity + IntoFilteredColumn>,
MP::Rhs: 'static + ColumnNumber,
{
fn solve_relaxation<IM>(&self) -> OptimizationResult<IM::F>
fn solve_relaxation<'provider, IM>(&'provider self) -> OptimizationResult<IM::F>
where
IM: InverseMaintener<F:
im_ops::FieldHR +
im_ops::Column<<<Self as MatrixProvider>::Column as Column>::F> +
im_ops::Cost<MP::Cost<'provider>> +
im_ops::Rhs<Self::Rhs> +
im_ops::Column<Self::Rhs> +
>,
for<'r> IM::F: im_ops::Cost<MP::Cost<'r>>,
{
let basis_indices = self.pivot_element_indices();
// Sorting of identity matrix columns
Expand Down
11 changes: 7 additions & 4 deletions src/algorithm/two_phase/phase_two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ use crate::algorithm::two_phase::tableau::kind::non_artificial::NonArtificial;
///
/// An `OptimizationResult` indicating whether or not the problem has a finite optimum. It cannot be
/// infeasible, as a feasible solution is needed to start using this method.
pub fn primal<IM, MP, PR>(
tableau: &mut Tableau<IM, NonArtificial<MP>>,
pub fn primal<'provider, IM, MP, PR>(
tableau: &mut Tableau<IM, NonArtificial<'provider, MP>>,
) -> OptimizationResult<IM::F>
where
IM: InverseMaintener<F: im_ops::FieldHR + im_ops::Column<<MP::Column as Column>::F>>,
for<'r> IM::F: im_ops::Cost<MP::Cost<'r>>,
IM: InverseMaintener<F:
im_ops::FieldHR +
im_ops::Column<<MP::Column as Column>::F> +
im_ops::Cost<MP::Cost<'provider>> +
>,
MP: MatrixProvider,
PR: PivotRule<IM::F>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/data/linear_algebra/vector/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ where
C: SparseComparator,
{
type F = F;
type Iter<'a> = SparseSliceIterator<'a, F>;
type Iter<'a> where C: 'a = SparseSliceIterator<'a, F>;

fn iter(&self) -> Self::Iter<'_> {
SparseSliceIterator::new(&self.data)
Expand Down
6 changes: 3 additions & 3 deletions src/tests/problem_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ pub fn artificial_tableau_form<MP: MatrixProvider<Column: ColumnTrait<F=T>, Rhs=
)
}

pub fn tableau_form<MP: MatrixProvider<Column: ColumnTrait<F=T>>>(
provider: &MP,
pub fn tableau_form<'provider, MP: MatrixProvider<Column: ColumnTrait<F=T>>>(
provider: &'provider MP,
) -> Tableau<Carry<S, BasisInverseRows<S>>, NonArtificial<MP>>
where
for<'a> S: im_ops::Cost<MP::Cost<'a>>,
S: im_ops::Cost<MP::Cost<'provider>>,
{
let carry = {
let minus_objective = RB!(-58);
Expand Down