#define RCSID "$Id: Generate_Network.c,v 1.12 2006/02/26 00:42:54 geuzaine Exp $" /* * Copyright (C) 1997-2006 P. Dular, C. Geuzaine * * 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 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. * * Please report all bugs and problems to . */ #include "GetDP.h" #include "Data_Active.h" #include "Treatment_Formulation.h" #include "Tools.h" /* ------------------------------------------------------------------------ */ /* G e n e r a t e _ N e t w o r k */ /* ------------------------------------------------------------------------ */ /* Determination of the matrix 'Loop - Branch' from the matrix 'Node - Branch' */ struct ConstraintActive * Generate_Network(List_T * ConstraintPerRegion_L) { struct ConstraintActive * Active ; struct ConstraintPerRegion * CPR ; List_T * ListInt_L ; int n, Nbr_Branch, Nbr_Loop, i, j, k, l ; int ** MatNode, ** MatLoop, ** MatA ; int * Flag_row, * Num_col, j_col1, j_col2 ; int vi, vk, vsum ; GetDP_Begin("Generate_Network"); /* List of the Nodes of the Network */ ListInt_L = List_Create(10, 10, sizeof(int)) ; Nbr_Branch = List_Nbr(ConstraintPerRegion_L) ; if (!Nbr_Branch) Msg(GERROR, "No branch in Network") ; for (j = 0 ; j < Nbr_Branch ; j++) { CPR = (struct ConstraintPerRegion *)List_Pointer(ConstraintPerRegion_L, j) ; List_Replace(ListInt_L, &(CPR->Case.Network.Node1), fcmp_int) ; List_Replace(ListInt_L, &(CPR->Case.Network.Node2), fcmp_int) ; } if (Nbr_Branch) List_Sort(ListInt_L, fcmp_int) ; n = List_Nbr(ListInt_L) - 1 ; /* Nbr_Node - 1 */ Nbr_Loop = Nbr_Branch - n ; /* Nbr of independent loops */ /* Active data */ Active = (struct ConstraintActive *)Malloc(sizeof(struct ConstraintActive)) ; Active->Case.Network.NbrNode = n ; Active->Case.Network.NbrBranch = Nbr_Branch ; Active->Case.Network.NbrLoop = Nbr_Loop ; Active->Case.Network.MatNode = MatNode = (int **)Malloc(n*sizeof(int *)); for (i=0 ; iCase.Network.MatLoop = MatLoop = (int **)Malloc(Nbr_Loop*sizeof(int *)); for (i=0 ; iCase.Network.Node1), fcmp_int)) > 0) MatNode[i-1][j] = -1 ; /* skip index 0, i.e. node 1 */ if ((i = List_ISearch(ListInt_L, &(CPR->Case.Network.Node2), fcmp_int)) > 0) MatNode[i-1][j] = 1 ; } /* Transformation of MatNode -> MatA ... Welsh algorithm */ MatA = (int **)Malloc(n*sizeof(int *)) ; for (i=0 ; i