Skip to content

Commit 62c9176

Browse files
committed
time improvement, julia script
1 parent d23be50 commit 62c9176

3 files changed

Lines changed: 69 additions & 4 deletions

File tree

Algorithms/StarBicoloringVertexCoverNonReq.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define PRECOL_STAR_BICOLORING_VERTEX_COVER_NON_REQ_M_H
77

88
#include "ColoringAlgorithms.h"
9-
#include "isets.h"
109

1110
/**
1211
* \brief Compute a star bicoloring of a bipartite graph GraphInstance (this version
@@ -615,7 +614,7 @@ class StarBicoloringVertexCoverNonReq : public ColoringAlgorithms{
615614

616615
IS.push_back((*di).first);
617616
}
618-
//Color vertices in independent set with color 0
617+
//Color vertices in an independent set with color 0
619618
for (vector<int>::iterator IS_it = IS.begin();
620619
IS_it != IS.end();
621620
++IS_it) {

mybuild/run_colpack.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616

1717
method_map = {
18-
"D2RestrictedColumns": "DISTANCE_TWO",
19-
"D2Columns": "DISTANCE_TWO"
18+
"D2RestrictedColumns": "COLUMN_PARTIAL_DISTANCE_TWO",
19+
"D2RestrictedRows": "ROW_PARTIAL_DISTANCE_TWO",
20+
"D2Columns": "COLUMN_PARTIAL_DISTANCE_TWO",
21+
"D2Rows": "ROW_PARTIAL_DISTANCE_TWO",
2022
}
2123

2224
# Function to extract metrics from ColPack output

mybuild/test_time.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using SparseMatrixColorings
2+
using MatrixMarket
3+
using SparseArrays
4+
using CSV
5+
using DataFrames
6+
7+
function color_mtx_file(filepath::String)
8+
println("\n==============================")
9+
println("Loading matrix from: $filepath")
10+
A = mmread(filepath)
11+
12+
println("Matrix size: ", size(A), ", nnz = ", nnz(A))
13+
14+
problem = ColoringProblem(; structure = :nonsymmetric, partition = :column)
15+
algo = GreedyColoringAlgorithm(; decompression = :direct)
16+
17+
# Measure time
18+
t = @elapsed result = coloring(A, problem, algo)
19+
20+
ncolors = maximum(column_colors(result))
21+
22+
# Report results
23+
println("Coloring took $(round(t, digits=4)) seconds")
24+
println("Number of colors used: $ncolors")
25+
26+
return (rows=size(A,1), cols=size(A,2), nnz=nnz(A), time=t, ncolors=ncolors)
27+
end
28+
29+
# Run from CSV and save results
30+
function run_from_csv(input_csv::String, output_csv::String)
31+
df = CSV.read(input_csv, DataFrame)
32+
33+
results = DataFrame(
34+
Matrix=String[],
35+
Rows=Int[],
36+
Cols=Int[],
37+
NNZ=Int[],
38+
TimeJulia=Float64[],
39+
NumberOfColorsJulia=Int[]
40+
)
41+
42+
for row in eachrow(df)
43+
filepath = row.Matrix
44+
try
45+
stats = color_mtx_file(filepath)
46+
push!(results, (
47+
filepath,
48+
stats.rows,
49+
stats.cols,
50+
stats.nnz,
51+
stats.time,
52+
stats.ncolors
53+
))
54+
catch e
55+
@warn "Failed to process $filepath" exception=(e, catch_backtrace())
56+
end
57+
end
58+
59+
CSV.write(output_csv, results)
60+
println("\n✅ Results written to $output_csv")
61+
end
62+
63+
# Example usage
64+
run_from_csv("input.csv", "Output/output_julia.csv")

0 commit comments

Comments
 (0)