import os, shutil, time
from random_qubo.random_qubo import RandomQubo
DIR = 'TEST_DATA' + "/" + time.strftime("%d_%m_%Y")
def getPath(filename = "", directory = ""):
    return DIR + "/" + directory + "/" + filename
    
bounds = {"matrix_q_lb": -5, "matrix_q_ub": 5, "c_lb": -5, "c_ub": 5}
DIR

shutil.rmtree(DIR, ignore_errors=True)
os.makedirs(getPath(directory = "SPARSE"))
os.makedirs(getPath(directory = "DENSE"))
os.makedirs(getPath(directory = "MULTIPLE"))
os.makedirs(getPath(directory = "CPLEX"))

# create sparse random qubos
# 3 variables connected
# start with 3x1 qubits
qaoa_max_qubits = 27 # number of qubits in Falcon r5.1 processors
var = 3
multiple = 1
while True:
    qp = RandomQubo.create_random_qubo("test_" + str(multiple), var, multiple=multiple, **bounds)              
    qp.write_to_lp_file(getPath(qp.name, directory = "SPARSE"))
    if qp.get_num_vars() > qaoa_max_qubits :
        print(multiple)
        break
    multiple = multiple + 1

# create dense random qubos
# start with 3 variables
while True:
    qp = RandomQubo.create_random_qubo("test_" + str(var), var, **bounds)              
    qp.write_to_lp_file(getPath(qp.name, directory = "DENSE"))
    if qp.get_num_vars() > qaoa_max_qubits :
        print(var)
        break
    var = var + 3

# create more test data for pegasus
# instances with several times the last instance which Mumbai is able to solve

# 27 variables each
# start with 27x2 qubits

var = qaoa_max_qubits
multiples = [2, 5, 10, 20]
for multiple in multiples:
    qp = RandomQubo.create_random_qubo("test_" + str(multiple), var, multiple=multiple, **bounds)              
    qp.write_to_lp_file(getPath(qp.name, directory = "MULTIPLE"))

qp = RandomQubo.create_random_qubo("test_cplex", 100, **bounds)     # used 10 for test data          
qp.write_to_lp_file(getPath(qp.name, directory = "CPLEX"))

