Package: data4co
Data4COA data generator tool for Combinatorial Optimization (CO) problems, enabling customizable, diverse, and scalable datasets for benchmarking optimization algorithms.Current supportdataProblemFirstImpl.SecondImpl.ThirdImpl.TSPtsplib✔LKH✔Concorde✔MISsatlib✔KaMIS📆----evaluatorProblemFirstImpl.SecondImpl.TSPtsplib✔uniform✔MISsatlib✔ER📆generatorProblemType1Impl.Type2Impl.Type3Impl.Type4Impl.TSPuniform✔gaussian✔cluster✔w/regret✔MISER✔BA✔HK✔WS✔solverProblemBaseImpl.FirstImpl.SecondImpl.TSPTSPSolver✔LKH✔Concorde✔MISMISSolver✔KaMIS✔Gurobi✔✔: Supported; 📆: Planned for future versions (contributions welcomed!).How to InstallGithubClone with the urlhttps://github.com/heatingma/Data4CO.git, and the following packages are required, and shall be automatically installed bypip:Python >= 3.8
numpy>=1.24.4
networkx==2.8.8
tsplib95==0.7.1
tqdm>=4.66.1
pulp>=2.8.0, 
pandas>=2.0.0,
scipy>=1.10.1PyPIIt is very convenient to directly use the following commandspip install data4coHow to Use Solver (TSPLKHSolver as example)fromdata4co.solverimportTSPLKHSolvertsp_lkh_solver=TSPLKHSolver(lkh_max_trials=500)tsp_lkh_solver.from_txt("path/to/read/file.txt")tsp_lkh_solver.solve()tsp_lkh_solver.evaluate()tsp_lkh_solver.to_txt("path/to/write/file.txt")How to Use Generator (TSPDataGenerator as example)fromdata4coimportTSPDataGeneratortsp_data_lkh=TSPDataGenerator(num_threads=8,nodes_num=50,data_type="uniform",solver="lkh",train_samples_num=16,val_samples_num=16,test_samples_num=16,save_path="path/to/save/")tsp_data_lkh.generate()How to Use Evaluator (TSPLIBEvaluator as example)>>>fromdata4co.evaluateimportTSPLIBEvaluator>>>fromdata4co.solverimportTSPLKHSolver,TSPConcordeSolver# test LKH>>>lkh_solver=TSPLKHSolver(lkh_scale=1e2)>>>eva=TSPLIBEvaluator()>>>eva.evaluate(lkh_solver)solved_costsgt_costsgapsa2802586.7696482586.7696480.000000e+00att4833523.70850733523.7085070.000000e+00berlin527544.3659027544.3659023.616585e-14ch1306110.7222006110.860950-2.270541e-03ch1506530.9027226532.280933-2.109847e-02eil101640.211591642.309536-3.266252e-01eil51428.871756429.983312-2.585113e-01eil76544.369053545.387552-1.867479e-01kroA10021285.44318221285.4431820.000000e+00kroC10020750.76250420750.7625040.000000e+00kroD10021294.29082121294.2908213.416858e-14lin10514382.99593314382.9959330.000000e+00pr1002260047.681630259066.6630533.786742e-01pr2392383849.940441378062.8261911.530728e+00pr76108159.438274108159.438274-1.345413e-14rd1007910.3962107910.3962100.000000e+00st70677.109609678.597452-2.192526e-01tsp2253859.0000003859.0000000.000000e+00AVG50007.05444449631.4488874.971646e-02# test concorde>>>con_solver=TSPConcordeSolver(concorde_scale=1e2)>>>eva.evaluate(con_solver)solved_costsgt_costsgapsa2802586.7696482586.769648-1.757974e-14att4833523.70850733523.7085072.170392e-14berlin527544.3659027544.3659020.000000e+00ch1306110.7222006110.860950-2.270541e-03ch1506530.9027226532.280933-2.109847e-02eil101640.211591642.309536-3.266252e-01eil51428.871756429.983312-2.585113e-01eil76544.369053545.387552-1.867479e-01kroA10021285.44318221285.443182-1.709139e-14kroC10020750.76250420750.7625040.000000e+00kroD10021294.29082121294.2908213.416858e-14lin10514382.99593314382.995933-1.264680e-14pr1002259066.663053259066.6630530.000000e+00pr2392378062.696085378062.826191-3.441403e-05pr76108159.438274108159.438274-1.345413e-14rd1007910.3962107910.396210-3.449238e-14st70677.109609678.597452-2.192526e-01tsp2253859.0000003859.0000000.000000e+00AVG49631.03983649631.448887-5.636336e-02