---
title: "Add Problem"
method: POST
path: "/problem/add"
---

# Add Problem

`POST /problem/add`

Add a newly defined problem to the database.

Args:
    request (Problem): the JSON representation of the problem.
    user (Annotated[User, Depends): the current user.
    session (Annotated[Session, Depends): the database session.

Note:
    Users with the role 'guest' may not add new problems.

Raises:
    HTTPException: when any issue with defining the problem arises.

Returns:
    ProblemInfo: the information about the problem added.

## Request body

- Problem — Model for a problem definition.
  - `name` string, required — Name of the problem.
  - `description` string, required — Description of the problem.
  - `constants` union[], nullable — Optional list of the constants present in the problem.
    - union
      - Constant — Model for a constant.
        - `name` string, required — Descriptive name of the constant. This can be used in UI and visualizations. Example: 'maximum cost'.
        - `symbol` string, required — Symbol to represent the constant. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'c_1'.
        - `value` union, required — The value of the constant.
          - number
          - integer
          - boolean
      - TensorConstant — Model for a tensor containing constant values.
        - `name` string, required — Descriptive name of the tensor representing the values. E.g., 'distances'
        - `symbol` string, required — Symbol to represent the constant. This will be used in the rest of the problem definition. Notice that the elements of the tensor will be represented with the symbol followed by indices. E.g., the first element of the third element of a 2-dimensional tensor, is represented by 'x_1_3', where 'x' is the symbol given to the TensorVariable. Note that indexing starts from 1.
        - `shape` integer[], required — A list of the dimensions of the tensor, e.g., `[2, 3]` would indicate a matrix with 2 rows and 3 columns.
        - `values` union, required
          - TensorInput[]
          - union[]
            - union
              - …
          - number
          - integer
          - boolean
          - 'List'
  - `variables` union[], required — List of variables present in the problem.
    - union
      - Variable — Model for a variable.
        - `name` string, required — Descriptive name of the variable. This can be used in UI and visualizations. Example: 'velocity'.
        - `symbol` string, required — Symbol to represent the variable. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'v_1'.
        - `variable_type` 'real' | 'integer' | 'binary', required — An enumerator for possible variable types.
        - `lowerbound` union — Lower bound of the variable.
          - number
          - integer
          - boolean
        - `upperbound` union — Upper bound of the variable.
          - number
          - integer
          - boolean
        - `initial_value` union — Initial value of the variable. This is optional.
          - number
          - integer
          - boolean
      - TensorVariable — Model for a tensor, e.g., vector variable.
        - `name` string, required — Descriptive name of the variable. This can be used in UI and visualizations. Example: 'velocity'.
        - `symbol` string, required — Symbol to represent the variable. This will be used in the rest of the problem definition. Notice that the elements of the tensor will be represented with the symbol followed by indices. E.g., the first element of the third element of a 2-dimensional tensor, is represented by 'x_1_3', where 'x' is the symbol given to the TensorVariable. Note that indexing starts from 1.
        - `variable_type` 'real' | 'integer' | 'binary', required — An enumerator for possible variable types.
        - `shape` integer[], required — A list of the dimensions of the tensor, e.g., `[2, 3]` would indicate a matrix with 2 rows and 3 columns.
        - `lowerbounds` union
          - TensorInput[]
          - union[]
            - union
              - …
          - number
          - integer
          - boolean
          - 'List'
        - `upperbounds` union — A list of lists, with the elements representing the upper bounds of each element. E.g., `[[1, 2, 3], [4, 5, 6]]`. If a single value is supplied, that value is assumed to be the upper bound of each element. Defaults to None.
          - union
            - TensorInput[]
            - union[]
              - …
            - number
            - integer
            - boolean
            - 'List'
          - number
          - integer
          - boolean
        - `initial_values` union — A list of lists, with the elements representing the initial values of each element. E.g., `[[1, 2, 3], [4, 5, 6]]`. If a single value is supplied, that value is assumed to be the initial value of each element. Defaults to None.
          - union
            - TensorInput[]
            - union[]
              - …
            - number
            - integer
            - boolean
            - 'List'
          - number
          - integer
          - boolean
  - `objectives` Objective[], required — List of the objectives present in the problem.
    - `name` string, required — Descriptive name of the objective function. This can be used in UI and visualizations. Example: 'time'.
    - `symbol` string, required — Symbol to represent the objective function. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'f_1'.
    - `unit` string, nullable — The unit of the objective function. This is optional. Used in UIs and visualizations. Example: 'seconds' or 'millions of hectares'.
    - `func` unknown[], nullable — The objective function. This is a JSON object that can be parsed into a function.Must be a valid MathJSON object. The symbols in the function must match the symbols defined for variable/constant/extra function. Can be 'None' for 'data_based', 'simulator' or 'surrogate' objective functions. If 'None', either 'simulator_path' or 'surrogates' must not be 'None'.
      - unknown
    - `simulator_path` string, path, nullable — Path to a python file with the connection to simulators. Must be a valid Path.Can be 'None' for 'analytical', 'data_based' or 'surrogate' objective functions.If 'None', either 'func' or 'surrogates' must not be 'None'.
    - `surrogates` string[], nullable — A list of paths to models saved on disk. Can be 'None' for 'analytical', 'data_based or 'simulator' objective functions. If 'None', either 'func' or 'simulator_path' must not be 'None'.
    - `maximize` boolean — Whether the objective function is to be maximized or minimized.
    - `ideal` number, nullable — Ideal value of the objective. This is optional.
    - `nadir` number, nullable — Nadir value of the objective. This is optional.
    - `objective_type` 'analytical' | 'data_based' | 'simulator' | 'surrogate' — An enumerator for supported objective function types.
    - `is_linear` boolean — Whether the function expression is linear or not. Defaults to `False`.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `scenario_keys` string[], nullable — Optional. The keys of the scenarios the objective function belongs to.
  - `constraints` Constraint[], nullable — Optional list of constraints present in the problem.
    - `name` string, required — Descriptive name of the constraint. This can be used in UI and visualizations. Example: 'maximum length'.
    - `symbol` string, required — Symbol to represent the constraint. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'g_1'.
    - `cons_type` '=' | '<=', required — An enumerator for supported constraint expression types.
    - `func` unknown[], nullable — Function of the constraint. This is a JSON object that can be parsed into a function.Must be a valid MathJSON object. The symbols in the function must match objective/variable/constant symbols.Can be 'None' if either 'simulator_path' or 'surrogates' is not 'None'. If 'None', either 'simulator_path' or 'surrogates' must not be 'None'.
      - unknown
    - `simulator_path` string, path, nullable — Path to a python file with the connection to simulators. Must be a valid Path.Can be 'None' for if either 'func' or 'surrogates' is not 'None'.If 'None', either 'func' or 'surrogates' must not be 'None'.
    - `surrogates` string[], nullable — A list of paths to models saved on disk. Can be 'None' for if either 'func' or 'simulator_path' is not 'None'. If 'None', either 'func' or 'simulator_path' must not be 'None'.
    - `is_linear` boolean — Whether the constraint is linear or not. Defaults to True, e.g., a linear constraint is assumed.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `scenario_keys` string[], nullable — Optional. The keys of the scenarios the constraint belongs to.
  - `extra_funcs` ExtraFunction[], nullable — Optional list of extra functions. Use this if some function is repeated multiple times.
    - `name` string, required — Descriptive name of the function. Example: 'normalization'.
    - `symbol` string, required — Symbol to represent the function. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'avg'.
    - `func` unknown[], nullable — The string representing the function. This is a JSON object that can be parsed into a function.Must be a valid MathJSON object. The symbols in the function must match symbols defined for objective/variable/constant.Can be 'None' if either 'simulator_path' or 'surrogates' is not 'None'. If 'None', either 'simulator_path' or 'surrogates' must not be 'None'.
      - unknown
    - `simulator_path` string, path, nullable — Path to a python file with the connection to simulators. Must be a valid Path.Can be 'None' for 'analytical', 'data_based' or 'surrogate' functions.If 'None', either 'func' or 'surrogates' must not be 'None'.
    - `surrogates` string[], nullable — A list of paths to models saved on disk. Can be 'None' for 'analytical', 'data_based or 'simulator' functions. If 'None', either 'func' or 'simulator_path' must not be 'None'.
    - `is_linear` boolean — Whether the function expression is linear or not. Defaults to `False`.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `scenario_keys` string[], nullable — Optional. The keys of the scenario the extra functions belongs to.
  - `scalarization_funcs` ScalarizationFunction[], nullable — Optional list of scalarization functions of the problem.
    - `name` string, required — Name of the scalarization function.
    - `symbol` string, nullable — Optional symbol to represent the scalarization function. This may be used in UIs and visualizations.
    - `func` unknown[], required — Function representation of the scalarization. This is a JSON object that can be parsed into a function.Must be a valid MathJSON object. The symbols in the function must match the symbols defined for objective/variable/constant/extra function.
      - unknown
    - `is_linear` boolean — Whether the function expression is linear or not. Defaults to `False`.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `scenario_keys` string[] — Optional. The keys of the scenarios the scalarization function belongs to.
  - `discrete_representation` DiscreteRepresentation — Model to represent discrete objective function and decision variable pairs. Can be used alongside an analytical representation as well. Used with Objectives of type 'data_based' by default. Each of the decision variable values and objective functions values are ordered in their respective dict entries. This means that the decision variable values found at `variable_values['x_i'][j]` correspond to the objective function values found at `objective_values['f_i'][j]` for all `i` and some `j`.
    - `variable_values` object, required — A dictionary with decision variable values. Each dict key points to a list of all the decision variable values available for the decision variable given in the key. The keys must match the 'symbols' defined for the decision variables.
    - `objective_values` object, required — A dictionary with objective function values. Each dict key points to a list of all the objective function values available for the objective function given in the key. The keys must match the 'symbols' defined for the objective functions.
    - `non_dominated` boolean — Indicates whether the representation consists of non-dominated points or not.If False, some method can employ non-dominated sorting, which might slow an interactive method down.
  - `scenario_keys` string[], nullable — Optional. The scenario keys defined for the problem. Each key will point to a subset of objectives, constraints, extra functions, and scalarization functions that have the same scenario key defined to them.If None, then the problem is assumed to not contain scenarios.
  - `simulators` Simulator[], nullable — Optional. The simulators used by the problem. Required when there are one or more Objectives defined by simulators. The corresponding values of the 'simulator' objective function will be fetched from these simulators with the given variable values.
    - `name` string, required — Descriptive name of the simulator. This can be used in UI and visualizations.
    - `symbol` string, required — Symbol to represent the simulator. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations.
    - `file` string, path, required — Path to a python file with the connection to simulators.
    - `parameter_options` object, nullable — Parameters to the simulator that are not decision variables, but affect the results.Format is similar to decision variables. Can be 'None'.
  - `is_convex` boolean, nullable — Optional. Used to manually indicate if the problem, as a whole, can be considered to be convex. If set to `None`, this property will be automatically inferred from the respective properties of other attributes.
  - `is_linear` boolean, nullable — Optional. Used to manually indicate if the problem, as a whole, can be considered to be linear. If set to `None`, this property will be automatically inferred from the respective properties of other attributes.
  - `is_twice_differentiable` boolean, nullable — Optional. Used to manually indicate if the problem, as a whole, can be considered to be twice differentiable. If set to `None`, this property will be automatically inferred from the respective properties of other attributes.

## Response `200`

Successful Response

- ProblemInfo — .
  - `name` string, required
  - `description` string, required
  - `is_convex` boolean, nullable, required
  - `is_linear` boolean, nullable, required
  - `is_twice_differentiable` boolean, nullable, required
  - `scenario_keys` string[], nullable, required
  - `variable_domain` 'continuous' | 'binary' | 'integer' | 'mixed', required — An enumerator for the possible variable type domains of a problem.
  - `id` integer, required
  - `user_id` integer, required
  - `constants` ConstantDB[], nullable, required
    - `name` string, required — Descriptive name of the constant. This can be used in UI and visualizations. Example: 'maximum cost'.
    - `symbol` string, required — Symbol to represent the constant. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'c_1'.
    - `value` number, required — The value of the constant.
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `tensor_constants` TensorConstantDB[], nullable, required
    - `values` union, required
      - TensorOutput[]
      - union[]
        - union
          - number
          - integer
          - boolean
      - number
      - integer
      - boolean
      - 'List'
    - `shape` integer[], required
    - `name` string, required — Descriptive name of the tensor representing the values. E.g., 'distances'
    - `symbol` string, required — Symbol to represent the constant. This will be used in the rest of the problem definition. Notice that the elements of the tensor will be represented with the symbol followed by indices. E.g., the first element of the third element of a 2-dimensional tensor, is represented by 'x_1_3', where 'x' is the symbol given to the TensorVariable. Note that indexing starts from 1.
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `variables` VariableDB[], nullable, required
    - `name` string, required — Descriptive name of the variable. This can be used in UI and visualizations. Example: 'velocity'.
    - `symbol` string, required — Symbol to represent the variable. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'v_1'.
    - `variable_type` 'real' | 'integer' | 'binary', required — An enumerator for possible variable types.
    - `lowerbound` number, nullable — Lower bound of the variable.
    - `upperbound` number, nullable — Upper bound of the variable.
    - `initial_value` number, nullable — Initial value of the variable. This is optional.
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `tensor_variables` TensorVariableDB[], nullable, required
    - `initial_values` union, required
      - TensorOutput[]
      - union[]
        - union
          - number
          - integer
          - boolean
      - number
      - integer
      - boolean
      - 'List'
    - `lowerbounds` union, required
      - TensorOutput[]
      - union[]
        - union
          - number
          - integer
          - boolean
      - number
      - integer
      - boolean
      - 'List'
    - `upperbounds` union, required
      - TensorOutput[]
      - union[]
        - union
          - number
          - integer
          - boolean
      - number
      - integer
      - boolean
      - 'List'
    - `shape` integer[], required
    - `name` string, required — Descriptive name of the variable. This can be used in UI and visualizations. Example: 'velocity'.
    - `symbol` string, required — Symbol to represent the variable. This will be used in the rest of the problem definition. Notice that the elements of the tensor will be represented with the symbol followed by indices. E.g., the first element of the third element of a 2-dimensional tensor, is represented by 'x_1_3', where 'x' is the symbol given to the TensorVariable. Note that indexing starts from 1.
    - `variable_type` 'real' | 'integer' | 'binary', required — An enumerator for possible variable types.
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `objectives` ObjectiveDB[], required
    - `func` unknown[], nullable, required
      - unknown
    - `scenario_keys` string[], nullable
    - `surrogates` string[], nullable
    - `simulator_path` string, path, nullable
    - `name` string, required — Descriptive name of the objective function. This can be used in UI and visualizations. Example: 'time'.
    - `symbol` string, required — Symbol to represent the objective function. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'f_1'.
    - `unit` string, nullable — The unit of the objective function. This is optional. Used in UIs and visualizations. Example: 'seconds' or 'millions of hectares'.
    - `maximize` boolean — Whether the objective function is to be maximized or minimized.
    - `ideal` number, nullable — Ideal value of the objective. This is optional.
    - `nadir` number, nullable — Nadir value of the objective. This is optional.
    - `objective_type` 'analytical' | 'data_based' | 'simulator' | 'surrogate' — An enumerator for supported objective function types.
    - `is_linear` boolean — Whether the function expression is linear or not. Defaults to `False`.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `constraints` ConstraintDB[], nullable, required
    - `func` unknown[], required
      - unknown
    - `scenario_keys` string[], nullable
    - `surrogates` string[], nullable
    - `simulator_path` string, path, nullable
    - `name` string, required — Descriptive name of the constraint. This can be used in UI and visualizations. Example: 'maximum length'.
    - `symbol` string, required — Symbol to represent the constraint. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'g_1'.
    - `cons_type` '=' | '<=', required — An enumerator for supported constraint expression types.
    - `is_linear` boolean — Whether the constraint is linear or not. Defaults to True, e.g., a linear constraint is assumed.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `scalarization_funcs` ScalarizationFunctionDB[], nullable, required
    - `func` unknown[], required
      - unknown
    - `scenario_keys` string[], required
    - `name` string, required — Name of the scalarization function.
    - `symbol` string, nullable — Optional symbol to represent the scalarization function. This may be used in UIs and visualizations.
    - `is_linear` boolean — Whether the function expression is linear or not. Defaults to `False`.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `extra_funcs` ExtraFunctionDB[], nullable, required
    - `func` unknown[], required
      - unknown
    - `scenario_keys` string[], nullable
    - `surrogates` string[], nullable
    - `simulator_path` string, path, nullable
    - `name` string, required — Descriptive name of the function. Example: 'normalization'.
    - `symbol` string, required — Symbol to represent the function. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations. Example: 'avg'.
    - `is_linear` boolean — Whether the function expression is linear or not. Defaults to `False`.
    - `is_convex` boolean — Whether the function expression is convex or not (non-convex). Defaults to `False`.
    - `is_twice_differentiable` boolean — Whether the function expression is twice differentiable or not. Defaults to `False`
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `discrete_representation` DiscreteRepresentationDB, required — The SQLModel equivalent to `DiscreteRepresentation`.
    - `non_dominated` boolean
    - `variable_values` object, required
    - `objective_values` object, required
    - `id` integer, nullable
    - `problem_id` integer, nullable
  - `simulators` SimulatorDB[], nullable, required
    - `file` string, path, required
    - `parameter_options` object, nullable
    - `name` string, required — Descriptive name of the simulator. This can be used in UI and visualizations.
    - `symbol` string, required — Symbol to represent the simulator. This will be used in the rest of the problem definition. It may also be used in UIs and visualizations.
    - `id` integer, nullable
    - `problem_id` integer, nullable

## Other responses

- `422` — Validation Error

## Changes

- **2025-05-20** `bbcc40488a72` — 2 breaking, 1 warning, 13 info
  - added required request body
  - removed the required property `problem_metadata` from the response with the `200` status
  - removed the optional property `simulators/anyOf[subschema #1]/items/url` from the response with the `200` status
  - the endpoint scheme security `APIKeyCookie` was removed from the API
  - …12 more

[Change history](https://skmtc.dev/industrial-optimization-group/apis/desdeo-fast-api/changes/problem/add/post.md)

---

[API](https://skmtc.dev/industrial-optimization-group/apis/desdeo-fast-api.md) · [All operations](https://skmtc.dev/industrial-optimization-group/apis/desdeo-fast-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/industrial-optimization-group/desdeo-fast-api/revisions/bbcc40488a72/schema)
