I am trying to create a randomly generated graph with the that takes 5 input parameters, n1, n2, p1, p2 and p3 and generates the random graph denoted G(n1, n2, p1, p2, p3) which has n1+n2 vertices partitioned into two sets V1, V2 such that |V1| = n1 and |V2| = n2.
p1, p2 and p3 are probabilities and therefore in the range 0 through 1. For every pair of vertices u, v ∈ V1, add an edge connecting u and v with probability p1. For every pair 1 of vertices u, v ∈ V2, add an edge connecting u and v with probability p2. For every pair of vertices u ∈ V1 and v ∈ V2, add an edge connecting u and v with probability p3.
Currently I have it making a random graph
private static ArrayList<LinkedList<Integer>> RandomGraph(int n1, int n2, double p1, double p2, double p3) {
int V = n1 + n2;
int[] verticies = new int[V];
// Fills up the verticies array
for (int i = 0; i < V; i++) {
verticies[i] = i;
}
// Shuffles the array
Random rand = new Random();
for (int i = 0; i < V; i++) {
int pos = i + rand.nextInt(V - i);
int temp = verticies[i];
verticies[i] = verticies[pos];
verticies[pos] = temp;
}
// System.out.println(Arrays.toString(verticies));
// V1
ArrayList<Edge> a = new ArrayList<>();
int i;
int j;
// for every pair so double for loop for each
for (i = 0; i < n1; i++) {
for (j = i + 1; j <= rand.nextInt(n1 - i) + i; j++) {
if(rand.nextDouble()<p1)
{
a.add(new Edge(verticies[i], verticies[j], p1));
a.add(new Edge(verticies[j], verticies[i], p1));
}
}
}
// V2
for (j = n1 + 1; j < V; j++) {
for (int k = j + 1; j <= rand.nextInt(V - k) + k; k++) {
if(rand.nextDouble<p2)
{
a.add(new Edge(verticies[j], verticies[k], p2));
a.add(new Edge(verticies[k], verticies[j], p2));
}
}
}
// V3
for (j = 0; j < n1; j++) {
for (int k = n1 + 1; k < V; k++) {
if(rand.nextDouble()<p3)
{
a.add(new Edge(verticies[j], verticies[k], p3));
a.add(new Edge(verticies[k], verticies[j], p3));
}
}
}
ArrayList<LinkedList<Integer>> Alist = new ArrayList<>();
for (j = 0; j < V; j++) {
Alist.add(new LinkedList<Integer>());
}
for (j = 0; j < a.size(); j++) {
Alist.get(a.get(j).start).add(a.get(j).end);
}
return Alist;
}
but I am not sure where the probabilities come into play. From what I have seen they come into when computing cost but I am not sure how to implement it into the graph generation.
Edit: Looked into Erdos-Renyi Model, but it doesnt really help when it comes to cost analysis? Added the implementation of ERM
Thank you for any help