Skip to content

Commit

Permalink
Merge pull request #12 from receptron/randomGraph
Browse files Browse the repository at this point in the history
Random graph
  • Loading branch information
snakajima authored May 2, 2024
2 parents 4d88aec + aecff25 commit 197ec22
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
39 changes: 39 additions & 0 deletions src/utils/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NodeData } from "graphai/lib/type";
const arrays = (num: number) => {
return new Array(num).fill(undefined);
};
const randomInt = (num: number) => {
return Math.floor(Math.random() * num);
}
export const generateGraph = () => {
const nodes: Record<string, NodeData> = {};
const inputsNode: string[] = [];
arrays(10).forEach((__i, k) => {
const name = "static_" + k;
inputsNode.push(name);
nodes[name] = {
value: name,
};
});

arrays(50).forEach((__i, k) => {
const name = "node_" + k;

const inputs = arrays(randomInt(4)).map(() => {
const rand = randomInt(inputsNode.length);
return inputsNode[rand];
});
nodes[name] = {
agentId: "sleepTestAgent",
params: {
duration: randomInt(10) * 400,
},
inputs,
};
inputsNode.push(name);
});

return {
nodes,
};
};
18 changes: 10 additions & 8 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { GraphAI, GraphData, AgentFunction } from "graphai";
import { NodeState, NodeData } from "graphai/lib/type";
import { pushAgent, popAgent } from "graphai/lib/experimental_agents/array_agents";
import { sleep } from "@/utils/utils";
import { generateGraph } from "@/utils/graph";
import cytoscape, {
// ElementDefinition,
Expand All @@ -55,7 +56,7 @@ import fcose from "cytoscape-fcose";
cytoscape.use(fcose);
const layouts = ["grid", "cose", "random", "circle", "concentric", "fcose", "breadthfirst"];
// const layouts = ["grid", "cose", "random", "circle", "concentric", "fcose", "breadthfirst"];
const calcNodeWidth = (label: string) => {
if (label === null || label === undefined) {
Expand Down Expand Up @@ -259,18 +260,20 @@ export default defineComponent({
components: {},
setup() {
const cyRef = ref();
const layout_value = ref(layouts[0]);
const cytoData = ref(cytoscapeFromGraph(graph_data2));
const res = ref({});
const logs = ref<unknown[]>([]);
let cy: null | Core = null;
const selectedGraphIndex = ref(0);
const graph_random = generateGraph();
const graphDataSet = [
{name: "sample2", data: graph_data2},
{name: "sample", data: graph_data},
{name: "random", data: graph_random},
];
const cytoData = ref(cytoscapeFromGraph(graphDataSet[0].data));
const res = ref({});
const logs = ref<unknown[]>([]);
let cy: null | Core = null;
const selectedGraph = computed(() => {
return graphDataSet[selectedGraphIndex.value].data;
});
Expand Down Expand Up @@ -372,7 +375,6 @@ export default defineComponent({
graph_data,
res,
cyRef,
layout_value,
selectedGraphIndex,
graphDataSet,
};
Expand Down

0 comments on commit 197ec22

Please sign in to comment.