AI4Finance-Foundation / RLSolver

Solvers for NP-hard and NP-complete problems with an emphasis on high-performance GPU computing.
https://ai4finance.org
MIT License
138 stars 32 forks source link

📝 GraphMaxCut: the solution_x of graph set 14, 15, 22, 49, 55, 70 #200

Open Yonv1943 opened 1 year ago

Yonv1943 commented 1 year ago

the solution_x of graph_set 14, 15, 22, 49, 50, 55, 70

Graph Score
g14 3029
g15 2995
g22 13167
g49 5712
g50 10012
g55 10017
g70 9358

SlnX14 denotes Solution X of Graph 14 """base64 string""" # the socre of this solution.

SlnX14 = """
2dbChJAXfdo2GRp49ecgPjQwfRSIJqcfANlGZMwwAOZzjFXMXFcLYmRi27fT49J38CH8NUHFf8nLFzuUQh_LltgK6ofnt0P2NEwwUdURMPtFC8ZhlzftdQJj
MQ1aEyvV6RqIv8
"""  # 3029

SlnX15 = """
AqOThDGdbjuzr7FAoXiCBgbwlc3lsy9bo2vb$KWBJ51OOIjkGcCBKwsQtu0zrlerpyWzpoAdOyeeoSMb3SoG$DSge$TNnfvsDwiivHk3JNFWTdXtiea2IEAg
$hxSFRWpKuqFo
"""  # 2995

SlnX22 = """
15M1wnHOEdRzp8Zws3XH0KzUDip$CCuC0dhgj9onOtyhWEbpH6hTzmSNozsdeNqM6jW7mwIC_nfrh1TYS8uz8St1$gz4rvd$8H5IfzhOOg3bXg7VS$4GtxyJ
$YothXUyFlOmUzaRwD31BeyYHKZPejOTcvXfcXsL$m$utCAABFN77HQCYHq5eNgTY9hy8oSivuLd09Crlz5AKI7u7ZNBKZPtOEM$sA00vFU9QmkX7e6JzPS3
32fItphr4PhDkGBFADHgVNBREHqPMO5BeIYPAah8chsT2ZesqvwFF2PE0zUbyNJY$2iYA1RCZWVxbPo1CqfgQaE5ddDWrF
"""  # 13167

SlnX49 = """
gggggrL9LLLLLggL9LLLLKgjQggggfLMhQggggjLAbLLLLQgbQLLLLLAhLgggggLLhMgggghLQhLLLLLgjQbLLLLIgLLAggggbALggggggggggrLLLLMfLLL
LLLLLLKgggggbQg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QHTj59uEqFDoypgm4ZvMlFub
z1rHQ4WSytr3OnZta42Au5Y7xatFdbl74dtyMJlXwVM9nNypB6VR_6fAkf_8phP7AtjEXzo0_4tkN59LphlPaQq2pLRqsNxskI9z2Q5TdoFmeb1xWkICPS4o
i5AB4LozUwz80VpPo4LDtVGIhs6jYME31mO0k6FoVh2i8gLRmL0wvqsBncNiaRNDahR5z1xuuGSERZQW1Gh98J7PBsYeVGsejp316q7yTPWR7nBnPQinyv1d
ULnnlmDdG8xSq6g1slTFR16ngzfCOgMNRdjbmpo8O1a9jpIJ8nrCYxiv$cFNedJJ3eRktLMXQ8QvqG_b7InRUfpmyYEFeR8bCvZTg7wZ_RgRRtP2$D3jApeD
sVKJ0hVuqQRNI3bWuEZNVPC_BhuQjsTMrKSQSH6YZCp7d5uRBpJbHI$fQT7s8RCkW5zA6GcY0Qt3YJS5j8mH918L28Os9$rK9MYIVlAMd7_
"""  # 9358

check the solution_x

def check_sln_x():
    graph_name, sln_x = 'gest_14', SlnX14

    env = GraphMaxCutEnv(graph_name=graph_name)
    best_sln_x = env.str_to_bool(sln_x)
    best_score = env.get_scores(best_sln_x.unsqueeze(0)).squeeze(0)
    print(f"NumNodes {env.num_nodes}  NumEdges {env.num_edges}")
    print(f"score {best_score}  sln_x \n{env.bool_to_str(best_sln_x)}")

convert the solustion_x from base64 string to tensor bool:

graph_name, sln_x = 'gest_14', SlnX14
env = GraphMaxCutEnv(graph_name=graph_name)
best_sln_x = env.str_to_bool(sln_x)

def write_result(result: Union[Tensor, List, np.array], filename: str = 'result/result.txt'):
    # assert len(result.shape) == 1
    # N = result.shape[0]
    num_nodes = len(result)
    directory = filename.split('/')[0]
    if not os.path.exists(directory):
        os.mkdir(directory)
    with open(filename, 'w', encoding="UTF-8") as file:
        for node in range(num_nodes):
            file.write(f'{node + 1} {int(result[node] + 1)}\n')