Current section
Files
Jump to
Current section
Files
lib/zog/.Elixir.Zog.Property.zig
// this code is autogenerated, do not check it into to your code repository
// ref lib/zog/property.ex:17
const std = @import("std");
const beam = @import("beam");
const zog = @import("zog");
const ArrayGraph = zog.models.ArrayGraph;
fn buildGraph(node_count: usize, from: []u32, to: []u32, weight: []f64) !ArrayGraph(void, f64) {
const allocator = beam.allocator;
var g = ArrayGraph(void, f64).init(allocator);
errdefer g.deinit();
try g.nodes.ensureTotalCapacity(allocator, node_count);
try g.edges.ensureTotalCapacity(allocator, from.len);
for (0..node_count) |_| {
_ = try g.addNode({});
}
for (from, to, weight) |f, t, w| {
_ = try g.addEdge(f, t, w);
}
return g;
}
pub fn all_maximal_cliques(node_count: usize, from: []u32, to: []u32, weight: []f64) ![][]u32 {
var g = try buildGraph(node_count, from, to, weight);
defer g.deinit();
return try zog.property.allMaximalCliques(beam.allocator, g);
}
pub fn nif_dsatur(node_count: usize, from: []u32, to: []u32, weight: []f64) ![]u32 {
var g = try buildGraph(node_count, from, to, weight);
defer g.deinit();
return try zog.property.dsatur(beam.allocator, g);
}
pub fn nif_exact_coloring(node_count: usize, from: []u32, to: []u32, weight: []f64, timeout_ms: u64) !beam.term {
var g = try buildGraph(node_count, from, to, weight);
defer g.deinit();
const res = try zog.property.exactColoring(beam.allocator, g, timeout_ms);
errdefer beam.allocator.free(res.colors);
const term = beam.make(.{.ok, res.chi, res.colors, res.timed_out}, .{});
beam.allocator.free(res.colors);
return term;
}