MQ

MQ

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  mixed quadratic equation

    Posted Tue January 02, 2024 01:52 PM
    def miq1(N, M, mu, p, C):
        print(f"M={M}, N={N}, Class {C}, mu = {mu}, p = {p}")
     
        # Create CPLEX model
        model = Model(name='MIQ1')
        
        # Set the OutputFlag parameter to 0 to suppress output
        model.parameters.output._details = 0
        
        # Set the time limit to 300 seconds
        model.parameters.timelimit = 300
     
     
        # Create decision variables x[j][m]
        x = {(j, m): model.binary_var(name=f'x_{j}_{m}') for j in range(N) for m in range(M)}
     
        # decision variables C[m]
        C = {m: model.continuous_var(name=f'C_{m}') for m in range(M)}
     
        # Create a new variable to represent the square root
        sqrt_expr = model.continuous_var(name='sqrt_expr', lb=0)
        # Add the quadratic constraint to ensure that sqrt_expr^2 is equal to the sum of squared terms
        model.add_constraint(sqrt_expr * sqrt_expr  == sum((C[m] - mu) ** 2 for m in range(M)))
        model.add_constraint(sqrt_expr >= 0)
     
        # Objective function
        obj_expr = sqrt_expr / mu
        model.minimize(obj_expr)
        
        # Constraints
        for j in range(N):
            model.add_constraint(sum(x[j, m] for m in range(M)) == 1)
     
        for m in range(M):
            model.add_constraint(C[m] == sum(x[j, m] * p[j] for j in range(N)))
     
        # Solve the model
        start_time = time.process_time()
        model.solve()
        solving_time = time.process_time() - start_time
     
        # Display the results
        for m in range(M):
            print(f"Machine {m + 1} completion time: {C[m].solution_value}")
     
        global nb_optimal
        if 'optimal' in model.solve_details.status.lower():
            nb_optimal += 1
        else:
            print("NO OPTIMAL")
            print(model.solve_details.status)
            solving_time=300
     
        return solving_time

    i have this mixed quadratic equation and I'm getting this error:
    Error: Model has non-convex quadratic constraint, index=0
    DOcplexException: Model<MIQ1> did not solve successfully

    Can anyone help me solve it?



    ------------------------------
    Georges Al Khoury
    ------------------------------


  • 2.  RE: mixed quadratic equation

    Posted Wed January 03, 2024 03:26 AM

    Wrong forum. This is about IBM MQ - a messaging system. 



    ------------------------------
    Mark Bluemel
    Software Engineer
    IBM
    mbluemel@uk.ibm.com
    ------------------------------