CSE505/Assignment2/A/randomgen.py
2024-03-09 23:16:18 +08:00

27 lines
995 B
Python

import random
import sys
if len(sys.argv) == 2: x = int(sys.argv[1])
else: x = 10
file1 = open("data" + str(x) + ".lp", "w")
file2 = open("data" + str(x) + ".py", "w")
file3 = open("data" + str(x) + ".dat", "w")
file4 = open("data" + str(x) + ".P", "w")
file2.write('[\n')
for i in range(x):
file1.write("node({}).\n".format(str(chr(ord('a') + i))))
file2.write('[')
for j in range(x):
k = random.randint(1,20)
if i != j:
file1.write("path({}, {}).\n".format(str(chr(ord('a') + i)), str(chr(ord('a') + j))))
file1.write("edge({}, {}, {}).\n".format(str(chr(ord('a') + i)), str(chr(ord('a') + j)), k))
file4.write("edge({}, {}, {}).\n".format(str(chr(ord('a') + i)), str(chr(ord('a') + j)), k))
file2.write(str(k))
file3.write("let dist[{}, {}] := {};\n".format(i+1, j+1,k))
if j != x - 1: file2.write(", ")
file2.write('],\n')
file2.write(']')
file1.close()
file2.close()
file3.close()
file4.close()