/* ASCEND modelling environment
Copyright (C) 2006 Carnegie Mellon University
Copyright (C) 1996 Benjamin Andrew Allan
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 2, 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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*//** @file
Sparse matrix permutation functions
Requires:
#include "utilities/ascConfig.h"
#include "mtx.h"
*//*
by Benjamin Andrew Allan
derived from mtx by Karl Michael Westerberg
Created: 5/3/90
Last in CVS: $Revision: 1.10 $ $Date: 1998/05/06 17:28:54 $ $Author: ballan $
*/
#ifndef ASC_MTX_PERMS_H
#define ASC_MTX_PERMS_H
/* the following block_perm functions are not yet implemented:
* this is the software spec. 5/3/95 baa. */
extern mtx_block_perm_t mtx_create_block_perm(mtx_matrix_t mtx);
/**<
*** Returns a token with the permutation/block information of the
*** mtx given. The mtx given must be previously output assigned and,
*** if it is to be partitioned, should already be partitioned.
*** The permutation returned can be used subsequently in various
*** ways, but all operations must be on the mtx the data came from.
*** If the matrix is reoutput assigned or repartitioned, the data
*** in bp becomes (potentially) invalid and should be completely
*** updated with mtx_update_block_perm.
*** Returns NULL if a bad mtx is detected.
***
*** Passes calls on slave matrices up to the master matrix.
***
-$- Checks extra carefully for a bad matrix, and returns NULL if so.
**/
extern int mtx_update_block_perm(mtx_matrix_t mtx,
int32 bnum,
mtx_block_perm_t bperm);
/**<
*** Given an mtx, a block number, and an existing bperm, this
*** routine updates the bperm permutation information about the
*** block bnum in the mtx.
*** The bperm updated must come from the mtx the bperm was created
*** for. The mtx must be output assigned and, if the mtx was
*** partitioned, the partition data must be consistent between the
*** bperm and the mtx. The mtx cannot have been resized.
***
*** Exceptions: If bnum is mtx_ALL_BLOCKS, we check only for the
*** mtx identity and output assignment. All previous permutation and
*** block information is ignored and replace by current info.
*** Calling with mtx_ALL_BLOCKS is substantially more expensive
*** than calling with a specific block number unless the block is
*** nearly the size of the problem.
***
*** Passes calls on slave matrices up to the master matrix.
***
*** Returns 1 from a bad matrix, 2 from a bad bperm, 3 from a mismatch.
*** Returns 0 from a successful call.
***
-$- Does excessive result checking, and then returns 3 if the
-$- excessive checks fail.
**/
extern int mtx_restore_block_perm(mtx_matrix_t mtx,
int32 bnum,
mtx_block_perm_t bperm);
/**<
*** Given an mtx, a block number, and an existing bperm, this
*** routine updates the mtx permutation information for the
*** block bnum using the bperm.
*** The mtx updated must go with the bperm.
*** The mtx must be output assigned and, if the mtx was
*** partitioned, the partition data must be consistent between the
*** bperm and the mtx. The mtx cannot have been resized.
*** The parity of the mtx will be set to that stored with the bperm;
*** if you try to do sneaky things, parity may get out of whack.
***
*** Exceptions: If bnum is mtx_ALL_BLOCKS, we check only for the
*** mtx identity and order. All previous permutation and
*** block information is ignored and replaced by bperm info.
*** The mtx's output_assigned and partition characteristics will
*** be restored to their values at the time the bperm was last
*** created or updated.
*** Calling with mtx_ALL_BLOCKS is substantially more expensive
*** than calling with a specific block number if all you really
*** want updated is a specific block.
***
*** Passes calls on slave matrices up to the master matrix.
***
*** Returns 1 from a bad matrix, 2 from a bad bperm, 3 from a mismatch.
*** Returns 0 from a successful call.
***
-$- Does excessive checking, and then returns usual values if the
-$- corresponding excessive checks fail.
**/
extern int mtx_destroy_block_perm(mtx_block_perm_t bperm);
/**<
*** Deallocates all memory associated with the bperm.
*** Has nothing to do with the matrix of bperm's origin.
*** Returns 1 if anything untoward happens during the
*** destruction. Returns 0 otherwise.
**/
extern size_t mtx_block_perm_size(mtx_block_perm_t bperm);
/**<
*** One for the bean counters. Returns current memory used by
*** the mtx_block_perm_t. Bytes as usual.
**/
/* end block_perm functions */
/*------------------------------------------------------------------------------
MTX PERMUTATION AND PERMUTATION INFO ROUTINES
*/
extern void mtx_swap_rows(mtx_matrix_t mtx, int32 row1, int32 row2);
/**<
*** Swaps two rows of the matrix. The association between the
*** "original row number" and the row contents is not
*** changed, so that some record is kept as to where a given row
*** originally came from (see mtx_org_to_row(), etc.).
***
*** Passes calls on slave matrices up to the master matrix.
-$- Does nothing to a bad matrix.
**/
ASC_DLLSPEC(void ) mtx_swap_cols(mtx_matrix_t mtx, int32 col1, int32 col2);
/**<
*** Swaps two columns of the matrix. The association between the
*** "original column number" and the column contents is not
*** changed, so that some record is kept as to where a given column
*** originally came from (see mtx_org_to_row(), etc.).
***
*** Passes calls on slave matrices up to the master matrix.
-$- Does nothing to a bad matrix.
**/
extern void mtx_drag(mtx_matrix_t mtx, int32 d1, int32 d2);
/**<
*** Drag shifts diagonal element d1 to position d2, or vice versa,
*** rotating all the intermediate elements as if d1 were swapped
*** (row and col) with all the intermediate di.
*** Drag exists because it is twice the speed of the following
*** implementation outside of mtx:
*** while( n1 < n2 ) { *** mtx_swap_rows(mtx,n1,n1+1); *** mtx_swap_cols(mtx,n1,n1+1); *** ++n1; *** } *** while( n1 > n2 ) { *** mtx_swap_rows(mtx,n1,n1-1); *** mtx_swap_cols(mtx,n1,n1-1); *** --n1; *** }*** If it turns out that a cycle_col or cycle_row (independent of diagonal) *** is wanted, implementation is now trivial. *** *** Passes calls on slave matrices up to the master matrix. -$- Does nothing to a bad matrix. **/ extern void mtx_reverse_diagonal(mtx_matrix_t mtx, int32 d1, int32 d2); /**< *** Does a series of symmetric permutations that reverses *** the ordering of the diagonal between (and including) d1 & d2. *** If d2 < d1, does nothing. *** *** Passes calls on slave matrices up to the master matrix. -$- Does nothing to a bad matrix. **/ ASC_DLLSPEC(int32 ) mtx_row_to_org(mtx_matrix_t mtx, int32 row); /**< Converts original row number <--> row number. Passes calls on slave matrices up to the master matrix. @return original row number, or -1 from a bad matrix. */ ASC_DLLSPEC(int32 ) mtx_col_to_org(mtx_matrix_t mtx, int32 col); /**< Converts original column number <--> column number. Passes calls on slave matrices up to the master matrix. @return original column numner, or -1 from a bad matrix. */ ASC_DLLSPEC(int32 ) mtx_org_to_row(mtx_matrix_t mtx, int32 orgrow); /**< Converts original row number <--> row number. Passes calls on slave matrices up to the master matrix. @return row number, or -1 from a bad matrix. */ ASC_DLLSPEC(int32 ) mtx_org_to_col(mtx_matrix_t mtx, int32 orgcol); /**< Converts original column number <--> column number. Passes calls on slave matrices up to the master matrix. @return column number, or -1 in case of a bad matrix. */ extern boolean mtx_row_parity(mtx_matrix_t mtx); /**< *** Returns the parity (even=FALSE,odd=TRUE) of the permutation which *** carries original row to current row numbers. *** Passes calls on slave matrices up to the master matrix. -$- Returns -1 from a bad matrix. **/ extern boolean mtx_col_parity(mtx_matrix_t mtx); /**< *** Returns the parity (even=FALSE,odd=TRUE) of the permutation which *** carries original column to current column numbers. *** Passes calls on slave matrices up to the master matrix. -$- Returns -1 from a bad matrix. **/ /*------------------------------------------------------------------------------ MTX STRUCTURAL MANIPULATION AND INFO ROUTINES */ extern int mtx_output_assign_region(mtx_matrix_t mtx, mtx_region_t *region, int *orphaned_rows); /**< *** This function is very similar to its sister function mtx_output_assign. *** It reorders the matrix to put as many non-zeros on the diagonal as *** possible. It mtx_ENTIRE_MATRIX is sent in as the region, the output *** assignment will affect the entire matrix. Otherwise the output *** assignment will be restricted to the designated region. *** This function returns the symbolic rank of the matrix. If a row can *** not be assigned it is moved to the end of lower edge of the matrix. *** The count of the unassigned aka orphaned rows is returned also. *** Unlike mtx_output_assign nothing else is done to the matrix.