/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "matrix.h"
#include
#include
#include
#include
namespace Graph {
using Eigen::Index;
//! check if coeff(r,c)==1
bool IncidenceMatrix::isSet( const Index r, const Index c) const
{
assert( coeff(r,c)<2 );
return coeff(r,c)==1;
}
bool IncidenceMatrix::isSet( const Index r, const last_t /*unused*/) const
{
return coeff(r,cols()-1)==1;
}
bool IncidenceMatrix::isSet( const last_t /*unused*/, const Index c) const
{
return coeff(rows()-1,c)==1;
}
//! Biadjacency matrix B = [O, A; A',O]
SparseMatrix IncidenceMatrix::biadjacency() const
{
const Index C = cols();
const Index R = rows();
// vector of triplets (i,j,value)
std::vector > tripletList;
for ( Index k=0; k::InnerIterator it(*this,k); it; ++it)
{
tripletList.emplace_back( it.row(), it.col()+R, it.value() );
tripletList.emplace_back( it.col()+R, it.row(), it.value() );
}
}
// create sparse matrix
SparseMatrix AA;
AA.resize( C+R, C+R );
AA.setFromTriplets( tripletList.begin(), tripletList.end() );
return AA;
}
//! remove column c
void IncidenceMatrix::remove_column( const Index c)
{
assert( c>=0 && c RR(C+1,C);
for (Index i=0; i=0 && r LL(R,R+1);
for (Index i=0; i=0 && r=0 && c LL( rows()-1,rows());
for ( Index i=0; i RR( cols(),cols()-1);
for ( Index i=0; i