-1

I'm trying to code MST4 in CPLEX, but because I'm new to code writing I have difficulty in doing it. I would really appreciate if anyone could help me. Thanks

1 Answer 1

0

In OPL tips and tricks see Minimum Spanning Tree

    tuple edge
    {
        key int o;
        key int d;
        int weight;
    }

    {edge} edges=...;

    {int} nodes={i.o | i in edges} union {i.d | i in edges};

    range r=1..-2+ftoi(pow(2,card(nodes)));
    {int} nodes2 [k in r] = {i | i in nodes: ((k div (ftoi(pow(2,(ord(nodes,i))))) mod 2) == 1)};

    dvar boolean x[edges];

    minimize sum (e in edges) x[e]*e.weight;
    subject to
    {
    sum(e in edges) x[e]==card(nodes)-1;

    // Subtour elimination constraints.
       
    forall(k in r)  // all subsets but empty and all
        sum(e in edges:(e.o in nodes2[k]) && (e.d in nodes2[k])) x[e]<=card(nodes2[k])-1;  
       
    }

    {edge} solution={e | e in edges : x[e]==1};

    execute
    {
    writeln("minimum spanning tree ",solution);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.