odow / StochOptFormat

Specification and description of the StochOptFormat file format
https://odow.github.io/StochOptFormat
MIT License
14 stars 2 forks source link

Changing modifications #1

Closed odow closed 4 years ago

odow commented 5 years ago

Currently, modifications are stored as a list of noise-terms, and each term has a list of modifications. I talked to @joaquimg about changing reversing this order, so we have a list of modifications, and each modification has a list with one element for each noise realization.

A concrete example:

Given two variables x >= 0 and y >= 0, we could store

noise_terms = [
    { x >= 1},
    { y >= 1}
]

or we could store

noise_terms = [
    { x >= 1, y >= 0},
    { x >= 0, y >= 1}
]

The upside is that the representation is easier to deal with, because otherwise we would have to take the union over everything that could change, and fill in the missing modifications with the base-case.

The downside is that if a coefficient differs from the base-case in only a few scenarios, then we are encoding a lot of redundant information. But this should get compressed out efficiently.

It'd look something like the following:

"modifications": {
    "type": "array",
    "items": {
        "type": "object",
        "required": ["probability", "noise_terms"],
        "properties": {
            "probability": {
                "type": "number",
                "minimum": 0.0,
                "maximum": 1.0
            },
            "noise_terms": {
                "$ref": "#/definitions/noise_term"
            }
        }
    }
}

"definitions": {
    "noise_term": {
        "type": "object",
        "required": ["head", "realizations"],
        "oneOf": [{
            "required": ["constraint"],
            "properties": {
                "head": {
                    "const": "NewSet"
                },
                "constraint": {
                    "description": "The name of the constraint we are changing.",
                    "type": "string"
                },
                "realizations": {
                    "type": "array",
                    "items": {
                        "oneOf": [{
                            "$ref": "https://raw.githubusercontent.com/odow/MathOptFormat/v0.2.1/mof.schema.json#/definitions/scalar_sets"
                        }, {
                            "$ref": "https://raw.githubusercontent.com/odow/MathOptFormat/v0.2.1/mof.schema.json#/definitions/vector_sets"
                        }]
                    }
                }
            }
        }, {
            "required": ["constraint", "variable"],
            "properties": {
                "head": {
                    "const": "ScalarCoefficientChange"
                },
                "constraint": {
                    "type": "string"
                },
                "variable": {
                    "type": "string"
                },
                "realizations": {
                    "type": "array",
                    "items": {
                        "type": "number"
                    }
                }
            }
        }]
    }
}