Skip to content
Snippets Groups Projects
Select Git revision
  • main
1 result

tssos_tests.jl

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    tssos_tests.jl 8.66 KiB
    using TSSOS, DynamicPolynomials, LinearAlgebra
    ## from Constrained Polynomial Optimization section of TSSOS' README
    @polyvar x[1:3]
    f = 1 + x[1]^4 + x[2]^4 + x[3]^4 + x[1]*x[2]*x[3] + x[2]
    g = 1 - x[1]^2 - 2*x[2]^2
    h = x[2]^2 + x[3]^2 - 1
    pop = [f, g]
    d = 2 # set the relaxation order
    opt,sol,data = cs_tssos_first(pop, x, d, numeq=0, TS="MD", CS="MD", Gram=true, solve=false);
    show_blocks(data, include_constraints=true)
    ##
    # *********************************** TSSOS ***********************************
    # TSSOS is launching...
    # -----------------------------------------------------------------------------
    # The clique sizes of varibles:
    # [list of different sizes of cliques]
    # [list of how many cliques have the sizes displayed]
    # -----------------------------------------------------------------------------
    ## list of (list of variables in clique)
    data.cliques
    ## = p in book notation = length(data.cliques)
    data.cql
    ## inequality constraints in each clique
    data.I
    ## equality constraints in each clique
    data.J
    ## J' from book - only non empty when deg(g_j) = deg(f) = 2r for all j
    data.ncc
    ##
    data.GramMat
    ##
    data.GramMat[1]
    ##
    data.GramMat[1][1]
    ## list of supports of pop data [f; g; h]
    # where the support of each polynomial = a list of (term = list of variables)
    data.supp
    ##
    show_blocks(data, include_constraints=true)
    ##basis[clique][constraint]
    data.basis[1]
    ##blocks[clique][constraint][block] -> indices of basis[clique][constraint] that appear in this block 
    data.blocks[1][1]
    ## what is the ts graph?
    opt,sol,data = cs_tssos_higher!(data, TS="MD", solve=false)
    show_blocks(data, include_constraints=true)
    ## plot correlative sparsity
    using Graphs, GLMakie, GraphMakie
    function cs_graph(pop, x, d; numeq, cs_alg="NC")
        opt,sol,data = cs_tssos_first(pop, x, d, numeq=numeq, CS=cs_alg, solve=false, solution=false);
    
        cs_graph(data), data
    end
    
    function cs_graph(data::TSSOS.mcpop_data)
        GCSP = SimpleGraph(length(data.x))
        for l = 1:data.cql
            TSSOS.add_clique!(GCSP, data.cliques[l])
        end
        GCSP
    end
    ## compute & plot CS graph of problem (after chordal extension)
    function node_drag_action_p(p, state, idx, event, axis)
        p[:node_pos][][idx] = event.data
        p[:node_pos][] = p[:node_pos][]
    end
    
    function plot_draggable(G; kwargs...)
        f, ax, p = graphplot(G; kwargs...)