Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

major refactor #13

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/docs/build/

.DS_Store

testing.jl
7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ authors = ["David Amos <[email protected]> and contributors"]
version = "0.1.0"

[deps]
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
Cbc = "1.0"
Graphs = "1.6"
HiGHS = "1.6.1"
JuMP = "1.1"
julia = "1.6"

Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ julia> using GraphInvariants
julia> g = cycle_graph(5)
{5, 5} undirected simple Int64 graph

julia> independence_number(g)
julia> compute(IndependenceNumber, g)
2
```

Expand All @@ -51,16 +51,12 @@ This project is still in its early stages. We plan to implement the following in
- [ ] Chromatic number
- [x] Clique number
- [x] Independence number
- [ ] Domination number
- [ ] Total domination number
- [x] Domination number
- [x] Total domination number
- [ ] Connected domination number
- [ ] Independent domination number
- [ ] Matching number
- [x] Independent domination number
- [x] Matching number
- [x] Residue
- [x] Zero forcing number

More invariants will be added in later versions, including:

- Zero forcing number
- Topological indices, like the Randić and Zagreb indices
- Residue
- And more...

176 changes: 168 additions & 8 deletions src/GraphInvariants.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,179 @@
module GraphInvariants

using Cbc
using Combinatorics
using Graphs
using HiGHS
using JuMP

include("independence/max_independent_set.jl")
include("independence/independence_number.jl")

# Include the graph operation rules module.
include("GraphRules/GraphRules.jl")
using .GraphRules

######################### Define Primary Abstract Types #################################

abstract type AbstractOptimalSet end
abstract type AbstractOptimalCardinality end
abstract type AbstractCardinality end
abstract type AbstractDegreeSequenceInvariant end

#################### Basic Graph Properties taken from Graphs.jl ##################

struct Order <: AbstractCardinality end
struct Size <: AbstractCardinality end

struct MaximumDegree <: AbstractCardinality end
struct MinimumDegree <: AbstractCardinality end
struct AverageDegree <: AbstractCardinality end

struct Radius <: AbstractCardinality end
struct Diameter <: AbstractCardinality end
struct Girth <: AbstractCardinality end

##################### Graph Optimal Sets and Cardinalities ##############################

struct MaximumIndependentSet <: AbstractOptimalSet end
struct IndependenceNumber <: AbstractOptimalCardinality end

struct MaximumClique <: AbstractOptimalSet end
struct CliqueNumber <: AbstractOptimalCardinality end

struct MinimumProperColoring <: AbstractOptimalSet end
struct ChromaticNumber <: AbstractOptimalCardinality end

struct MinimumDominatingSet <: AbstractOptimalSet end
struct DominationNumber <: AbstractOptimalCardinality end

struct MinimumTotalDominatingSet <: AbstractOptimalSet end
struct TotalDominationNumber <: AbstractOptimalCardinality end

struct MinimumLocatingDominatingSet <: AbstractOptimalSet end
struct LocatingDominationNumber <: AbstractOptimalCardinality end

struct MinimumPairedDominatingSet <: AbstractOptimalSet end
struct PairedDominationNumber <: AbstractOptimalCardinality end

struct MinimumIndependentDominatingSet <: AbstractOptimalSet end
struct IndependentDominationNumber <: AbstractOptimalCardinality end

struct MinimumEdgeDominatingSet <: AbstractOptimalSet end
struct EdgeDominationNumber <: AbstractOptimalCardinality end

struct MinimumPowerDominatingSet <: AbstractOptimalSet end
struct PowerDominationNumber <: AbstractOptimalCardinality end

struct MaximumMatching <: AbstractOptimalSet end
struct MatchingNumber <: AbstractOptimalCardinality end

struct MinimumZeroForcingSet <: AbstractOptimalSet end
struct ZeroForcingNumber <: AbstractOptimalCardinality end

##################### Graphical Degree Sequence Invariants ##############################

struct SlaterNumber <: AbstractDegreeSequenceInvariant end
struct HavelHakimiResidue <: AbstractDegreeSequenceInvariant end
struct AnnihilationNumber <: AbstractDegreeSequenceInvariant end
struct SubTotalDominationNumber <: AbstractDegreeSequenceInvariant end
struct SubKDominationNumber <: AbstractDegreeSequenceInvariant
k::Int
end
SubKDominationNumber(;k=1) = SubKDominationNumber(k)

##################### Graphical Degree Sequence Operations ##############################



#############################################################################################

# Include files from src.

include("basics/from_graphs.jl")

include("cliques/maximimum_clique.jl")
include("cliques/clique_number.jl")

include("chromatic_colorings/proper_colorings.jl")
include("chromatic_colorings/chromatic_number.jl")

include("degree_sequence_invariants/havel_hakimi_residue.jl")
include("degree_sequence_invariants/slater.jl")
include("degree_sequence_invariants/annihilation.jl")

include("domination/minimum_dominating_sets.jl")
include("domination/domination_numbers.jl")

include("independence/independence_number.jl")
include("independence/max_independent_set.jl")

include("matching/matching_sets.jl")
include("matching/matching_number.jl")

include("zero_forcing/minimum_zero_forcing_set.jl")
include("zero_forcing/zero_forcing_number.jl")

# Exports
export AbstractOptimalSet
export AbstractOptimalCardinality
export DegreeSequenceInvariant
export GraphRule

export Order
export Size
export Girth

export MaximumDegree
export MinimumDegree
export AverageDegree

export Radius
export Diameter

export MaximumIndependentSet
export IndependenceNumber

export MaximumClique
export CliqueNumber

export MinimumProperColoring
export ChromaticNumber

export MinimumDominatingSet
export DominationNumber
export DominationRule

export MinimumTotalDominatingSet
export TotalDominationNumber

export MinimumLocatingDominatingSet
export LocatingDominationNumber

export MinimumPairedDominatingSet
export PairedDominationNumber

export MinimumPowerDominatingSet
export PowerDominationNumber

export MinimumIndependentDominatingSet
export IndependentDominationNumber

export MinimumEdgeDominatingSet
export EdgeDominationNumber

export MaximumMatching
export MatchingNumber

export MinimumZeroForcingSet
export ZeroForcingNumber
export ZeroForcingRule

# independence
export max_independent_set
export independence_number
export HavelHakimiRule
export HavelHakimiResidue
export SlaterNumber
export AnnihilationNumber
export SubTotalDominationNumber
export SubKDominationNumber

# cliques
export clique_number
export apply!
export compute

end
29 changes: 29 additions & 0 deletions src/GraphRules/GraphRules.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module GraphRules

using Graphs

######################### Define Primary Abstract Types #################################
abstract type AbstractGraphRule end
abstract type AbstractDegreeSequenceRule end

############################ Graph Operations as Rules ##################################

struct DominationRule <: AbstractGraphRule end
struct ZeroForcingRule <: AbstractGraphRule end

##################### Graphical Degree Sequence Operations ##############################

struct HavelHakimiRule <: AbstractDegreeSequenceRule end


######################### Include the Primary Functions #################################
include("domination_rule.jl")
include("zero_forcing_rule.jl")
include("havel_hakimi.jl")

######################### Export the Primary Types and Apply Function ##################
export AbstractGraphRule, AbstractDegreeSequenceRule
export DominationRule, HavelHakimiRule, ZeroForcingRule
export apply!

end
9 changes: 9 additions & 0 deletions src/GraphRules/domination_rule.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function apply!(
::Type{DominationRule},
target_set::Set{Int},
g::AbstractGraph,
)
for v in copy(target_set) # use copy to avoid modifying set during iteration
union!(target_set, neighbors(g, v))
end
end
Loading