{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://automationglance.com/quantum-compiler/schemas/problem.v1.schema.json",
  "title": "AutomationGlance QPC problem v1",
  "type": "object",
  "properties": {
    "schemaVersion": {
      "const": "automationglance.qpc.problem.v1"
    },
    "family": {
      "enum": [
        "maxcut",
        "knapsack",
        "assignment",
        "qubo"
      ]
    },
    "name": {
      "type": "string",
      "maxLength": 256,
      "default": ""
    },
    "description": {
      "type": "string",
      "maxLength": 8192,
      "default": ""
    },
    "settings": {
      "type": "object",
      "properties": {
        "target": {
          "enum": [
            "ocean",
            "neutral"
          ],
          "default": "ocean"
        },
        "penalty": {
          "anyOf": [
            {
              "type": "number",
              "minimum": -1000000,
              "maximum": 1000000,
              "exclusiveMinimum": 0
            },
            {
              "type": "null"
            }
          ],
          "default": null
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "metadata": {
      "type": "object",
      "maxProperties": 32,
      "propertyNames": {
        "maxLength": 128
      },
      "additionalProperties": {
        "type": "string",
        "maxLength": 1024
      }
    },
    "data": {
      "type": "object"
    }
  },
  "required": [
    "schemaVersion",
    "family",
    "data"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "family": {
            "const": "maxcut"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "#/$defs/maxcut"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "family": {
            "const": "knapsack"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "#/$defs/knapsack"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "family": {
            "const": "assignment"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "#/$defs/assignment"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "family": {
            "const": "qubo"
          }
        }
      },
      "then": {
        "properties": {
          "data": {
            "$ref": "#/$defs/qubo"
          }
        }
      }
    }
  ],
  "$defs": {
    "maxcut": {
      "type": "object",
      "properties": {
        "vertices": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
          },
          "minItems": 1,
          "maxItems": 2048
        },
        "edges": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "source": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "target": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "weight": {
                "type": "number",
                "minimum": -1000000,
                "maximum": 1000000
              }
            },
            "required": [
              "source",
              "target",
              "weight"
            ],
            "additionalProperties": false
          },
          "minItems": 0,
          "maxItems": 100000
        }
      },
      "required": [
        "vertices",
        "edges"
      ],
      "additionalProperties": false
    },
    "knapsack": {
      "type": "object",
      "properties": {
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "weight": {
                "type": "integer",
                "minimum": 1,
                "maximum": 127
              },
              "value": {
                "type": "integer",
                "minimum": 1,
                "maximum": 1000
              }
            },
            "required": [
              "id",
              "weight",
              "value"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 2048
        },
        "capacity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 127
        }
      },
      "required": [
        "items",
        "capacity"
      ],
      "additionalProperties": false
    },
    "assignment": {
      "type": "object",
      "properties": {
        "tasks": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
          },
          "minItems": 1,
          "maxItems": 2048
        },
        "workers": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "capacity": {
                "type": "integer",
                "minimum": 0,
                "maximum": 2048,
                "default": 1
              }
            },
            "required": [
              "id"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 2048
        },
        "costs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "task": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "worker": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "cost": {
                "type": "number",
                "minimum": -1000000,
                "maximum": 1000000
              }
            },
            "required": [
              "task",
              "worker",
              "cost"
            ],
            "additionalProperties": false
          },
          "minItems": 1,
          "maxItems": 2048
        }
      },
      "required": [
        "tasks",
        "workers",
        "costs"
      ],
      "additionalProperties": false
    },
    "qubo": {
      "type": "object",
      "properties": {
        "variables": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
          },
          "minItems": 1,
          "maxItems": 2048
        },
        "terms": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "i": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "j": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^\\u0000-\\u001f\\u007f]+$"
              },
              "coefficient": {
                "type": "number",
                "minimum": -1000000,
                "maximum": 1000000
              }
            },
            "required": [
              "i",
              "j",
              "coefficient"
            ],
            "additionalProperties": false
          },
          "minItems": 0,
          "maxItems": 100000
        },
        "offset": {
          "type": "number",
          "minimum": -1000000,
          "maximum": 1000000,
          "default": 0
        },
        "convention": {
          "const": "distinct-pairs-once",
          "default": "distinct-pairs-once"
        }
      },
      "required": [
        "variables",
        "terms"
      ],
      "additionalProperties": false
    }
  }
}

