// // Allow a mixing of SM and SR using the morphing technique // "graph morph (type B)" in AAAI-99 // import java.util.*; public class SMSRInstance { Random gen; int n; // number of agents, even int m; // number of edges ArrayList[] pref; // preference list of agents ArrayList cliqueE; // all possible edges ArrayList bicliqueE; // all possible edges in bipatrite graph ArrayList mixE; // edges in mixed SM & SR, of size m boolean trace; void shuffle(ArrayList v){ int j,n; n = v.size(); int temp; for (int i=n-1;i>0;i--){ j = gen.nextInt(i+1); temp = v.get(i); v.set(i,v.get(j)); v.set(j,temp); } } // // Knuth shuffle of integer vector // SMSRInstance(int n){ gen = new Random(); this.n = n; this.pref = new ArrayList[n]; m = (n*n)/4; // number of edges cliqueE = new ArrayList(); // all possible edges bicliqueE = new ArrayList(); // all possible edges mixE = new ArrayList(); // edges in mixed SM & SR, of size m for (int i=0;i(); } void build(String modelType,double p){ if (modelType.equals("A")) buildTypeA(p); if (modelType.equals("B")) buildTypeB(p); } void buildTypeB(double p){ int mSR = (int)(p*m); // number of edges to select from SR int mSM = m - mSR; // number of edges to select from SM int mIntersection = 0; // thes size of the intersection between smE and srE ArrayList srE = new ArrayList(); // edges in SR (with same number of edges in SM) ArrayList smE = new ArrayList(); // edges in SM ArrayList deleteE = new ArrayList(); // edges to delete mixE.clear(); // // create edges in complete bipartite graph smE // for (int i=0;i additions = new ArrayList(); mixE.clear(); // // create a random SM instance with mSM edges // shuffle(bicliqueE); for (int i=0;i0;i++){ int edge = cliqueE.get(i); if (!mixE.contains(edge)){ mixE.add(edge); additions.add(edge); mSR--; } } // //Create preference lists // displayEdges("sr: ",additions); displayEdges("mix:",mixE); for (int i=0;i)pref[i]) System.out.print((j+1) +" "); System.out.println(); } } void displayEdges(String name,ArrayList E){ if (!trace) return; System.out.print(name +" "); System.out.print("|"+ E.size() +"| "); for (int e : E) System.out.print("("+ (e/n+1) +","+ (e%n+1) +") "); System.out.println(); } public static void main(String args[]){ int n = Integer.parseInt(args[0]); // must be even double p = Double.parseDouble(args[1]); // (1.0-p) from SM (p=0 <-> SM), p from SR (p=1 <-> SR) SMSRInstance inst = new SMSRInstance(n); inst.trace = args.length > 3; if (args[2].equals("A")) inst.buildTypeA(p); if (args[2].equals("B")) inst.buildTypeB(p); inst.display(); } }