Skip to content

Commit

Permalink
julia formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
harshangrjn committed Aug 24, 2022
1 parent 5096109 commit c8bc43c
Show file tree
Hide file tree
Showing 23 changed files with 987 additions and 694 deletions.
8 changes: 8 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Configuration file for JuliaFormatter.jl
# For more information, see: https://domluna.github.io/JuliaFormatter.jl/stable/config/

always_for_in = true
always_use_return = true
margin = 90
remove_extra_newlines = true
short_to_long_function_def = true
31 changes: 31 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: format-check
on:
push:
branches:
- master
- release-*
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- uses: actions/checkout@v1
- name: Format check
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
using JuliaFormatter
format("src/MOI_wrapper", verbose=true)
format("test", verbose=true)
out = String(read(Cmd(`git diff`)))
if isempty(out)
exit(0)
end
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
LaplacianOpt.jl Change Log
=========================

### v0.3.1
- Minor change in `src/variables.jl`
- Added JuliaFormatter.toml and formatting workfow

### v0.3.0
- Includes adjacency of base and augments graphs in results dictionary
- Constraints added to support cycle graphs with max algberaic connectivity using `hamiltonian_cycle` in `graph_type`
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LaplacianOpt"
uuid = "bb20392f-64fb-4001-92e8-14b3aedd5a9e"
authors = ["Harsha Nagarajan"]
version = "0.3.0"
version = "0.3.1"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
27 changes: 16 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ using DocumenterTools: Themes
for w in ("light", "dark")
header = read(joinpath(@__DIR__, "src/assets/themes/style.scss"), String)
theme = read(joinpath(@__DIR__, "src/assets/themes/$(w)defs.scss"), String)
write(joinpath(@__DIR__, "src/assets/themes/$(w).scss"), header*"\n"*theme)
write(joinpath(@__DIR__, "src/assets/themes/$(w).scss"), header * "\n" * theme)
end

Themes.compile(joinpath(@__DIR__, "src/assets/themes/light.scss"), joinpath(@__DIR__, "src/assets/themes/documenter-light.css"))
Themes.compile(joinpath(@__DIR__, "src/assets/themes/dark.scss"), joinpath(@__DIR__, "src/assets/themes/documenter-dark.css"))
Themes.compile(
joinpath(@__DIR__, "src/assets/themes/light.scss"),
joinpath(@__DIR__, "src/assets/themes/documenter-light.css"),
)
Themes.compile(
joinpath(@__DIR__, "src/assets/themes/dark.scss"),
joinpath(@__DIR__, "src/assets/themes/documenter-dark.css"),
)

makedocs(
modules = [LaplacianOpt],
sitename = "LaplacianOpt",
format = Documenter.HTML(mathengine = Documenter.MathJax(),
prettyurls = get(ENV, "CI", nothing) == "true"),
format = Documenter.HTML(
mathengine = Documenter.MathJax(),
prettyurls = get(ENV, "CI", nothing) == "true",
),
strict = true,
authors = "Harsha Nagarajan",
pages = [
"Introduction" => "index.md",
"Quick Start guide" => "quickguide.md",
"Introduction" => "index.md",
"Quick Start guide" => "quickguide.md",
"Function References" => "function_references.md",
],
)

deploydocs(
repo = "github.com/harshangrjn/LaplacianOpt.jl.git",
push_preview = true
)
deploydocs(repo = "github.com/harshangrjn/LaplacianOpt.jl.git", push_preview = true)
51 changes: 28 additions & 23 deletions examples/optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,57 @@
#=====================================#

function get_gurobi()
return JuMP.optimizer_with_attributes(Gurobi.Optimizer,
MOI.Silent() => false,
# "MIPFocus" => 3, # Focus on optimality over feasibility
"Presolve" => 1)
return JuMP.optimizer_with_attributes(
Gurobi.Optimizer,
MOI.Silent() => false,
# "MIPFocus" => 3, # Focus on optimality over feasibility
"Presolve" => 1,
)
end

function get_cplex()
return JuMP.optimizer_with_attributes(CPLEX.Optimizer,
MOI.Silent() => false,
# "CPX_PARAM_EPGAP" => 1E-4,
# "CPX_PARAM_MIPEMPHASIS" => 2 # Focus on optimality over feasibility
"CPX_PARAM_PREIND" => 1)
return JuMP.optimizer_with_attributes(
CPLEX.Optimizer,
MOI.Silent() => false,
# "CPX_PARAM_EPGAP" => 1E-4,
# "CPX_PARAM_MIPEMPHASIS" => 2 # Focus on optimality over feasibility
"CPX_PARAM_PREIND" => 1,
)
end

#======================================#
# MIP solvers (open-source, but slow) #
#======================================#

function get_cbc()
return JuMP.optimizer_with_attributes(Cbc.Optimizer,
MOI.Silent() => false)
return JuMP.optimizer_with_attributes(Cbc.Optimizer, MOI.Silent() => false)
end

function get_glpk()
return JuMP.optimizer_with_attributes(GLPK.Optimizer,
MOI.Silent() => false)
return JuMP.optimizer_with_attributes(GLPK.Optimizer, MOI.Silent() => false)
end

#========================================================#
# Continuous nonlinear programming solver (open-source) #
#========================================================#

function get_ipopt()
return JuMP.optimizer_with_attributes(Ipopt.Optimizer,
MOI.Silent() => true,
"sb" => "yes",
"max_iter" => Int(1E4))
return JuMP.optimizer_with_attributes(
Ipopt.Optimizer,
MOI.Silent() => true,
"sb" => "yes",
"max_iter" => Int(1E4),
)
end


#=================================================================#
# Local mixed-integer nonlinear programming solver (open-source) #
#=================================================================#
function get_juniper()
return JuMP.optimizer_with_attributes(Juniper.Optimizer,
MOI.Silent() => false,
"mip_solver" => get_gurobi(),
"nl_solver" => get_ipopt())
end
return JuMP.optimizer_with_attributes(
Juniper.Optimizer,
MOI.Silent() => false,
"mip_solver" => get_gurobi(),
"nl_solver" => get_ipopt(),
)
end
39 changes: 21 additions & 18 deletions examples/run_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ lopt_optimizer = get_cplex()
#=
Option I: Let the package parse a JSON file and obtain the data dictionary (data_dict)
Sample JSON format: Check examples/instances
=#
=#
function data_I()
num_nodes = 8
instance = 1
instance = 1
# Data format has to be as given in this JSON file
file_path = joinpath(@__DIR__, "instances/$(num_nodes)_nodes/$(num_nodes)_$(instance).json")
file_path =
joinpath(@__DIR__, "instances/$(num_nodes)_nodes/$(num_nodes)_$(instance).json")
data_dict = LOpt.parse_file(file_path)
augment_budget = (num_nodes-1) # spanning tree constraint
augment_budget = (num_nodes - 1) # spanning tree constraint
return data_dict, augment_budget
end

Expand All @@ -34,7 +35,7 @@ end
num_nodes, adjacency_base_graph and adjacency_augment_graph
=#
function data_II()
data_dict = Dict{String, Any}()
data_dict = Dict{String,Any}()
data_dict["num_nodes"] = 4
data_dict["adjacency_base_graph"] = [0 2 0 0; 2 0 3 0; 0 3 0 4; 0 0 4 0]
data_dict["adjacency_augment_graph"] = [0 0 4 8; 0 0 0 7; 4 0 0 0; 8 7 0 0]
Expand All @@ -47,23 +48,25 @@ end
#-------------------------------#
data_dict, augment_budget = data_II()

params = Dict{String, Any}(
"data_dict" => data_dict,
"augment_budget" => augment_budget,
"eigen_cuts_full" => true,
params = Dict{String,Any}(
"data_dict" => data_dict,
"augment_budget" => augment_budget,
"eigen_cuts_full" => true,
"soc_linearized_cuts" => false,
"eigen_cuts_2minors" => false,
"eigen_cuts_3minors" => false,
"topology_flow_cuts" => true,
"eigen_cuts_2minors" => false,
"eigen_cuts_3minors" => false,
"topology_flow_cuts" => true,
# "time_limit" => 3600,
)
)

#----------------------------------------------------------------#
# Optimization model and visualize solution (optional) #
# Graph plots can be located inside `examples/plots` folder #
#----------------------------------------------------------------#
result = LOpt.run_LOpt(params,
lopt_optimizer;
visualize_solution = false, # Make this true to plot the graph solution
visualizing_tool = "tikz", # "graphviz" is another option
display_edge_weights = false)
result = LOpt.run_LOpt(
params,
lopt_optimizer;
visualize_solution = false, # Make this true to plot the graph solution
visualizing_tool = "tikz", # "graphviz" is another option
display_edge_weights = false,
)
15 changes: 9 additions & 6 deletions src/LaplacianOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Graphs
import TikzGraphs
import TikzPictures

const MOI = MathOptInterface
const LA = LinearAlgebra
const MOI = MathOptInterface
const LA = LinearAlgebra
const LOpt = LaplacianOpt

# Create our module level logger (this will get precompiled)
const _LOGGER = Memento.getlogger(@__MODULE__)

Expand All @@ -22,13 +22,16 @@ __init__() = Memento.register(_LOGGER)

"Suppresses information and warning messages output by LaplacianOpt, for fine grained control use the Memento package"
function silence()
Memento.info(_LOGGER, "Suppressing information and warning messages for the rest of this session. Use the Memento package for more fine-grained control of logging.")
Memento.setlevel!(Memento.getlogger(LaplacianOpt), "error")
Memento.info(
_LOGGER,
"Suppressing information and warning messages for the rest of this session. Use the Memento package for more fine-grained control of logging.",
)
return Memento.setlevel!(Memento.getlogger(LaplacianOpt), "error")
end

"allows the user to set the logging level without the need to add Memento"
function logger_config!(level)
Memento.config!(Memento.getlogger("LaplacianOpt"), level)
return Memento.config!(Memento.getlogger("LaplacianOpt"), level)
end

include("data.jl")
Expand Down
Loading

0 comments on commit c8bc43c

Please sign in to comment.