Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Graph coloring

    Posted Tue August 07, 2012 08:46 AM

    Originally posted by: cdvolko


    Hi,

    I'm new to CPLEX. I want to use it to solve a graph coloring problem exactly. Here's my code:

    void calculateChromaticNumberExact ()
    {
    int i, j, numSubgraphs = graph->getNumSubgraphs (), numNodes = graph->getNumNodes ();
    IloEnv env;
    IloModel mod (env);
    IloIntVar x numSubgraphs;

    for (i = 0; i < numSubgraphs; i++)
    {
    mod.add (x [i] >= 0);
    mod.add (x [i] <= numSubgraphs - 1);
    mod.add (IloMinimize (env, x [i]));
    for (j = 0; j < i; j++)
    if (graph->getEdge (i * numNodes + j))
    mod.add (x [i] != x[j]);
    }

    IloCplex cplex (mod);
    cplex.solve ();

    chromaticNumberExact = cplex.getObjValue ();
    }

    This compiles, but it throws IloWrongUsage and terminates. What am I doing wrong?

    x [i] is supposed to be the color of node i. If there is an edge between nodes i and j, x [i] must be != x [j]. The minimum number of colors is sought for.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Graph coloring

    Posted Wed August 08, 2012 10:58 AM

    Originally posted by: cdvolko


    I have also tried following the recommendations for an integer program formulation of this problem more closely, but this does not even compile due to IloSum:
    void calculateChromaticNumberExact ()
    {
    int i, j, k, numSubgraphs = graph->getNumSubgraphs (), numNodes = graph->getNumNodes ();
    IloEnv env;
    IloModel mod (env);
    IloIntVar x numSubgraphs numSubgraphs;

    for (i = 0; i < numSubgraphs; i++)
    {
    mod.add (IloSum (x [i]) == 1);
    for (j = 0; i < numSubgraphs; i++)
    {
    mod.add (x [i] [j] >= 0);
    mod.add (x [i] [j] <= 1);
    }
    for (k = 0; k < i; k++)
    if (graph->getEdge (i * numNodes + k))
    for (j = 0; j < numSubgraphs; j++)
    mod.add (x [i] [j] + x [k] [j] <= 1);
    }

    IloCP cp (mod);
    cp.solve ();

    chromaticNumberExact = cp.getObjValue ();
    }

    Please help.
    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: Graph coloring

    Posted Wed August 08, 2012 07:56 PM

    Originally posted by: SystemAdmin


    There may or may not be errors in your code, but unless you surround it with {code}, it's hard to tell. The forum software translates parts of code into italics, "links" or other artifacts that make it hard to read the code.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: Graph coloring

    Posted Tue September 18, 2012 04:33 AM
    Hi,

    if you are a beginner, maybe writing a model in OPL would be easier for you.
    Could that be an option?

    regards
    #DecisionOptimization
    #MathematicalProgramming-General


  • 5.  Re: Graph coloring

    Posted Wed September 19, 2012 02:35 AM

    Originally posted by: SystemAdmin


    You need to surround you code snippet with '{code}' tags, otherwise we cannot read it.
    As far as I can tell you never initialize the elements in the 'x' array? That would be a problem.
    Could you please tell us which statement in your code throws the exception?
    #DecisionOptimization
    #MathematicalProgramming-General


  • 6.  RE: Re: Graph coloring

    Posted 12 hours ago

    Graph coloring is a simple way to assign colors to different points (nodes) in a graph so that no connected points have the same color. It helps make complex connections easier to understand and visually clear.Just like choosing colors for clarity, fun activities such as sanrio hello kitty coloring pages also use colors to create clear and enjoyable designs.



    ------------------------------
    Globe sim
    ------------------------------