/*************************************************************************** func.cpp - description ------------------- begin : Wed Mar 13 2002 copyright : (C) 2002 by Sven Klauke email : sklauke@wiwi.uni-bielefeld.de Institute of Mathematical Economics (IMW) University of Bielefeld, Germany http://www.wiwi.uni-bielefeld.de/~imw/ ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ extern "C"{ #include "balance.h" } #include #include #include "func.h" #include "leastcore.h" #include int member(int n, int player, int coalition) { return (coalition >> (n-player-1)) % 2; } /* check_linspan: - returns 1, if the profile vector of coalition k_new is in the linear span of the profile vectors of the coalitions in k, returns 0 otherwise - called from main.cpp within the balancedness check (not implemented in current version 0.1) - calls linear_span in balance.c */ int check_linspan(int n, vector k,int k_new) { int i,j; int s=(int)k.size(); vector > p(n,s+1); for(i=0;i> (n-i-1)) % 2; for(j=0;j> (n-i-1)) % 2; } int *pptr[n]; for(i=0;i k) { int i,j; int s=(int)k.size(); vector > p(n+s,s+1); for(i=0;i> (n-i-1)) % 2); } int *pptr[n+s]; for(i=0;i > leastcore(int n,vector v,int flag_redundant) { int k=(int)pow(2,n); int i,j; int p[k-1][n+2]; for(i=1;i> (n-j-1)) % 2; p[i-1][n+1]=1; } p[k-2][0]=v[k-1]; for(i=0;i > lc(lc_size); vector lc_elem(n); ifstream fin("lc"); // file containg the vertices of the least core string inp; do{ fin >> inp;}while(inp!="rational"); for(i=0;i> inp; for(j=0;j> x; lc_elem[j]=x; } lc[i]=lc_elem; } return lc; } /* setup_and_calc_lp: - sets up and solves the intermediate linear program in the calculation of the prenucleolus - returns the vertices of the region of optimal solutions - called from main.cpp - calls calc_lp in leastcore .c - the vertices are written in file "lc" by calc_lp */ vector > setup_and_calc_lp(int n,vector v, vector coalitions, int flag_redundant) { int k=(int)pow(2,n); int i,j; int p[coalitions.size()+1][n+2]; for(i=0;i<(int)coalitions.size();i++) { p[i][0]=-1*v[coalitions[i]]; for(j=0;j> (n-j-1)) % 2; p[i][n+1]=1; } p[coalitions.size()][0]=v[k-1]; for(i=0;i > lp(lp_size); vector lp_elem(n); ifstream fin("lc"); string inp; do{ fin >> inp;}while(inp!="rational"); for(i=0;i> inp; for(j=0;j> x; lp_elem[j]=x; } lp[i]=lp_elem; } return lp; }