1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
<html>
<head>
<title>JSXGraph Konstruktionstemplate</title>
<link rel="stylesheet" type="text/css" href="/jsxgraph/distrib/jsxgraph.css" />
<script type="text/javascript" src="../src/loadjsxgraph.js"></script>
<script type="text/javascript" src="../src/reader/graph.js"></script>
</head>
<body>
<div id="jxgbox" class="jxgbox" style="width:500px; height:500px;"></div>
<script type="text/javascript">
/* <![CDATA[ */
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-4,4,12,-4], keepaspectratio:true,axis:true});
// drawRandomGraph(board, 8, 0.3, false, 17); // gewichtet, mit Gewichten zwischen 1 und 17
// drawRandomGraph(board, 8, 0.3, false, 1); // ungewichtet
drawRandomGraph(board, 8, 0.5, true, 1); // gerichtet, ungewichtet (8 Knoten, Wahrscheinlichkeit 0,3, dass zwischen zwei Knoten eine Kante gezeichnet wird)
function produceRandomGraph(n, p, directed, weighted) { // n is the number of nodes; p is the chance for two given points to get an edge between them
var i,j, adjMatrix = [], nodes = [], nodenumbers = {}, number;
for(i=0; i<n; i++) {
adjMatrix[i] = [];
if(directed) {
for(j=0; j<n; j++) {
if(j<i) {
if(adjMatrix[j][i] != 1) {
if(Math.random()<p) {
if(weighted == 1) {
adjMatrix[i][j] = 1;
}
else {
adjMatrix[i][j] = Math.round(Math.random()*(weighted-1))+1;
}
}
else {
adjMatrix[i][j] = 0;
}
}
}
else {
if(Math.random()<p) {
if(weighted == 1) {
adjMatrix[i][j] = 1;
}
else {
adjMatrix[i][j] = Math.round(Math.random()*(weighted-1))+1;
}
}
else {
adjMatrix[i][j] = 0;
}
}
}
}
else {
adjMatrix[i][i] = 0;
for(j=0; j<i; j++) {
if(Math.random()<p) {
if(weighted = 1) {
adjMatrix[i][j] = 1;
adjMatrix[j][i] = 1;
}
else {
number = Math.round(Math.random()*(weighted-1))+1;
adjMatrix[i][j] = number;
adjMatrix[j][i] = number;
}
}
else {
adjMatrix[i][j] = 0;
adjMatrix[j][i] = 0;
}
}
}
nodes[i] = {name:'A_'+i,coords:[null,null]}
nodenumbers['A_'+i] = i;
}
return {n:n, nodes:nodes, adjMatrix:adjMatrix, nodenumbers: nodenumbers, weighted: (weighted != 1), directed: directed}
}
function drawRandomGraph(board, n, p, directed, maxweight) { // maxweight == 1 => not weighted
var graph;
graph = produceRandomGraph(n, p, directed, maxweight);
board.addedGraph = graph;
JXG.GraphReader.drawGraph(graph, board);
}
</script>
</body>
</html>
|