parameters: (self, linear_expr, negate=False)
return_statement: return result
docstring: Returns a LinearExpressionProto built from a LinearExpr instance.
docstring_summary: Returns a LinearExpressionProto built from a LinearExpr instance.
docstring_tokens: Returns a LinearExpressionProto built from a LinearExpr instance .
function: def ParseLinearExpression(self, linear_expr, negate=False):
          """Returns a LinearExpressionProto built from a LinearExpr instance."""
          result = cp_model_pb2.LinearExpressionProto()
          mult = -1 if negate else 1
          if cmh.is_integral(linear_expr):
              result.offset = int(linear_expr) * mult
              return result
  
          if isinstance(linear_expr, IntVar):
              result.vars.append(self.GetOrMakeIndex(linear_expr))
              result.coeffs.append(mult)
              return result
  
          coeffs_map, constant = linear_expr.GetIntegerVarValueMap()
          result.offset = constant * mult
          for t in coeffs_map.items():
              if not isinstance(t[0], IntVar):
                  raise TypeError('Wrong argument' + str(t))
              c = cmh.assert_is_int64(t[1])
              result.vars.append(t[0].Index())
              result.coeffs.append(c * mult)
          return result
function_tokens: def ParseLinearExpression ( self , linear_expr , negate = False ) : result = cp_model_pb2 . LinearExpressionProto ( ) mult = - 1 if negate else 1 if cmh . is_integral ( linear_expr ) : result . offset = int ( linear_expr ) * mult return result if isinstance ( linear_expr , IntVar ) : result . vars . append ( self . GetOrMakeIndex ( linear_expr ) ) result . coeffs . append ( mult ) return result coeffs_map , constant = linear_expr . GetIntegerVarValueMap ( ) result . offset = constant * mult for t in coeffs_map . items ( ) : if not isinstance ( t [ 0 ] , IntVar ) : raise TypeError ( 'Wrong argument' + str ( t ) ) c = cmh . assert_is_int64 ( t [ 1 ] ) result . vars . append ( t [ 0 ] . Index ( ) ) result . coeffs . append ( c * mult ) return result