JuliaManifolds / JuliaManifolds/ManoptExamples.jl
Graph stability number
- Dominant language
- Julia
- Stars
- 9
- Forks
- 1
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 1
Description
I've found new potential example when searching for papers about Hager-Zhang on manifolds: https://arxiv.org/pdf/2207.01855.pdf . In case it would be useful:
```julia
struct GraphStabilityNumberCost
g::Graph
end
function (c::GraphStabilityNumberCost)(x)
cost = mapreduce(t -> t^4, +, x)
for e in edges(c.g)
cost += x[e.src]^2 * x[e.dst]^2
end
return cost
end
function (c::GraphStabilityNumberCost)(::Manifolds.Sphere, x)
return c(x)
end
struct GraphStabilityNumberGrad!
g::Graph
end
function (c::GraphStabilityNumberGrad!)(storage, x)
for i in 1:length(x)
storage[i] = 4 * x[i]^3
end
for e in edges(c.g)
storage[e.src] += 2 * x[e.src] * x[e.dst]^2
storage[e.dst] += 2 * x[e.src]^2 * x[e.dst]
end
return storage
end
function (c::GraphStabilityNumberGrad!)(M::Manifolds.Sphere, storage, x)
c(storage, x)
riemannian_gradient!(M, storage, x, storage)
return storage
end
"""
GraphStabilityNumberCost
Problem 4.2 from https://arxiv.org/pdf/2207.01855.pdf .
"""
function make_gsn_problem(n::Int, k::Int)
g = Graphs.SimpleGraphs.SimpleGraph(n, k)
return GraphStabilityNumberCost(g), GraphStabilityNumberGrad!(g)
end
```
Contributor guide
Assessment
This issue has not been assessed yet.