// Finding maximum matching via ascending auction // Section 17.4 of Karlin and Peres, "Game Theory, Alive" // Lowest and highest envy-free price vectors and utility vectors, section 17.2 // Theorem 17.2.6 // Also does envy-free rent division, section 17.3 // Coded with rationals to avoid floating point issues #include #include #define MAXN (100) #define UNMATCHED (-1) void error(char *str,int num) { printf("%s %d\n",str,num); exit(num); } void readInput(int *n,int v[MAXN][MAXN]) { scanf("%d",n); if (*n<1 || *n>MAXN) error("range",__LINE__); for (int i=0; i<*n; i++) for (int j=0; j<*n; j++) { scanf("%d",&v[i][j]); if (v[i][j]<0) error("range",__LINE__); } } int ascendingAuction(int n,int v[MAXN][MAXN],int m[MAXN]) { int deltaNum=1; // Numerator for delta, denominator is n+1 int matchCard; // Cardinality of matching int sum=0; int vNum[MAXN][MAXN]; // numerator for rational form of v, denominator is n+1 int mInverse[MAXN]; // inverse of m[] int pNum[MAXN]; // Numerator for price, denominator is n+1 // Convert v to rational form for (int i=0; i=pNum[j]) { // Test the candidate match for (k=0; ksumHighest) printf("Desired rent is outside of fairness range\n"); else { // See KP p. 305 double alpha=(sumHighest-desiredRentTotal)/(sumHighest-sumLowest); printf("Envy-free prices using alpha %f:\n",alpha); for (int i=0; i