| 1 | /* -*- mode: C++ -*- */ |
|---|
| 2 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 3 | // FILE : define.random.graph.tol |
|---|
| 4 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | |
|---|
| 6 | //Random seed setting |
|---|
| 7 | Real If(ObjectExist("Real","rndSeed"), |
|---|
| 8 | PutRandomSeed(rndSeed), |
|---|
| 9 | PutRandomSeed(0)); |
|---|
| 10 | Real If(ObjectExist("Real","rndSeed"), rndSeed, |
|---|
| 11 | rndSeed = GetRandomSeed(0)); |
|---|
| 12 | |
|---|
| 13 | WriteLn("Current Random Seed = "<<rndSeed); |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | Real If(ObjectExist("Real","vertex.num"), vertex.num, |
|---|
| 17 | vertex.num = IntRand(2,1000) ); |
|---|
| 18 | Real If(ObjectExist("Real","edge.num"), edge.num, |
|---|
| 19 | edge.num = IntRand(1,(vertex.num)^1.5) ); |
|---|
| 20 | Real If(ObjectExist("Real","directed"), directed, |
|---|
| 21 | directed = IntRand(0,1) ); |
|---|
| 22 | Real If(ObjectExist("Real","removeRepeatedEdges"), removeRepeatedEdges, |
|---|
| 23 | removeRepeatedEdges = IntRand(0,1) ); |
|---|
| 24 | |
|---|
| 25 | WriteLn("Creating "+If(directed,"directed","symmetric")+ |
|---|
| 26 | " graph with "<<vertex.num+ " vertices and close to "<< |
|---|
| 27 | edge.num+" edges ..."); |
|---|
| 28 | Real t0 = Copy(Time); |
|---|
| 29 | |
|---|
| 30 | GraphTools::@Graph graph = GraphTools::@Graph::New("test_0001",directed); |
|---|
| 31 | |
|---|
| 32 | Set vertex.names = For(1,vertex.num,Text(Real k) |
|---|
| 33 | { |
|---|
| 34 | "Key_"<<FormatReal(k,"%06.0f")<< |
|---|
| 35 | "_"+FormatReal(IntRand(0,999999999),"%09.0lf") |
|---|
| 36 | }); |
|---|
| 37 | |
|---|
| 38 | Real graph::initialize(vertex.names); |
|---|
| 39 | |
|---|
| 40 | Real graph::_.edge::add.feature.numeric("Length"); |
|---|
| 41 | Real graph::_.edge::add.feature.numeric("Hight"); |
|---|
| 42 | |
|---|
| 43 | VMatrix data = Mat2VMat( |
|---|
| 44 | { InOut = RandCombination(edge.num,vertex.num,2) } | |
|---|
| 45 | { Length = Rand(edge.num, 1, 10, 100) } | |
|---|
| 46 | { Hight = Rand(edge.num, 1, 1, 10) }); |
|---|
| 47 | |
|---|
| 48 | Real graph::edge.build(data,removeRepeatedEdges); |
|---|
| 49 | |
|---|
| 50 | Real t1 = Copy(Time); |
|---|
| 51 | |
|---|
| 52 | WriteLn("Creating time "<<(t1-t0)+" seconds"); |
|---|