92 lines
1.7 KiB
SQL
92 lines
1.7 KiB
SQL
/**
|
|
** Initializes a random graph from the subgraph of the WWW graph by
|
|
** assigning probabilities to the edges in the following way:
|
|
** p(u,v) = degree(u) / max degree(w)
|
|
**
|
|
** Assumes as input two tables n0(u) and e0(u,v).
|
|
*/
|
|
|
|
|
|
drop table to_subset cascade;
|
|
drop table in_degree;
|
|
drop table out_degree;
|
|
|
|
drop table e1;
|
|
|
|
drop table edge0;
|
|
drop table no_edge0;
|
|
|
|
drop table edge;
|
|
|
|
drop table no_edge;
|
|
|
|
/*
|
|
Create random graph example
|
|
*/
|
|
|
|
create table in_degree as
|
|
(
|
|
select v, count(*) as d
|
|
from e0
|
|
group by v
|
|
)
|
|
union
|
|
(
|
|
select u, 0 as d
|
|
from e0
|
|
where u not in (select v from e0)
|
|
);
|
|
|
|
|
|
create table out_degree as
|
|
(
|
|
select u, count(*) as d
|
|
from e0
|
|
group by u
|
|
)
|
|
union
|
|
(
|
|
select v, 0 as d
|
|
from e0
|
|
where v not in (select u from e0)
|
|
);
|
|
|
|
|
|
|
|
create table e1
|
|
as select e0.u, e0.v, 1 as bit, o.d::float4 / (select max(d) from out_degree)::float4 as p
|
|
from e0, out_degree o
|
|
where e0.u = o.u;
|
|
|
|
insert into e1
|
|
select u, v, 0 as bit, 1 - p as p
|
|
from e1
|
|
where p != 1;
|
|
|
|
|
|
/* This table represents all subsets of the total order over node as possible
|
|
worlds.
|
|
*/
|
|
create table to_subset as
|
|
(
|
|
repair key u,v in e1
|
|
weight by p
|
|
);
|
|
|
|
|
|
create table edge0 as (select u,v from to_subset where bit=1);
|
|
create table no_edge0 as (select u,v from to_subset where bit=0);
|
|
|
|
/* add the missing edges to no_edge0 */
|
|
insert into no_edge0
|
|
select n1.u as u, n2.u as v
|
|
from n0 n1, n0 n2
|
|
where (n1.u,n2.u) not in (select u,v from e0);
|
|
|
|
|
|
--create table edge as (select * from edge0);
|
|
--insert into edge (select v as u, u as v from edge0);
|
|
|
|
--create table no_edge as (select * from no_edge0);
|
|
--insert into no_edge (select v as u, u as v from no_edge0);
|