40 lines
1.0 KiB
PL/PgSQL
40 lines
1.0 KiB
PL/PgSQL
/**
|
|
** Initializes relaitons storing a subgraph of the WWW graph.
|
|
** Creates tables n0(u) and e0(u,v) for the nodes and edges of the subgraph,
|
|
** respectively. The function expects the WWW graph to be given by relations
|
|
** n and e, and accepts as parameter number r giving the ratio of the original
|
|
** graph nodes to retain.
|
|
**/
|
|
|
|
drop table n0;
|
|
drop table e0;
|
|
|
|
/*
|
|
Create a node relation
|
|
*/
|
|
create table n0 (u integer);
|
|
create table e0 (u integer, v integer);
|
|
|
|
drop function init_www_nodes(float4 );
|
|
create or replace function init_www_nodes(r float4) returns void as
|
|
$$
|
|
DECLARE
|
|
i int;
|
|
|
|
BEGIN
|
|
/* create a subset of the node relation by keepeing nodes uniformly at random
|
|
with the specified probability r */
|
|
insert into n0
|
|
select * from n
|
|
where random() < r;
|
|
|
|
/* compute the edge relation induced by the subset of the nodes n0 */
|
|
insert into e0
|
|
select * from e
|
|
where u in (select u from n0) and v in (select u from n0);
|
|
|
|
RETURN;
|
|
END;
|
|
$$
|
|
language plpgsql;
|