# Setting up Objective function for CQM

I have previoulsy used BQM model for computation for problems. However I want to stup the same problem as an CQM by expressingthe cnstraints explicitly and not introducing them into the objective as penalties, nd also change the type of variables to 'REAL".

However I am not sure how to construct the objectvie function, as in CQM we don't have methods like : add_quadratic_from , ```add_linear_from``` , etc.  as it dos in case of BQMs.

Can someone help me on this ?

1 comment
• There are two methods to add an objective function to a CQM object.

• Build a BQM(or Quadratic Model if your problem has real or integer variables) and add it to the CQM. Here is a minimal code example:
`from dimod import ConstrainedQuadraticModel, BinaryQuadraticModel#Define BQM or QMbqm = BinaryQuadraticModel()bqm.add_linear_from({'i': 2})bqm.add_quadratic_from({('i','j'): -0.5})#Set objectivecqm = ConstrainedQuadraticModel()cqm.set_objective(bqm)`
• Set the objective function using symbolic math. This method is specially useful for small models used for experimenting and formulating problems.
```from dimod import Binary, ConstrainedQuadraticModel
i = Integer('i')
j = Integer('j')