optimizationjuliaconstraintspiecewisejulia-jump# Define Piecewise Function as a Constraint in Julia

I have an optimization model to which I need to add the following piecewise function as a constraint:

```
C_{i,k} = { PR_{i} * HSE_{k} i∈Ω, k = 1,...,M,
1 i∈Ω, k = 1,...,M
```

I read PR and HSE from excel cells

¿Is there a nice way to do this in Julia? I have not found any documentation on this in Julia

Solution

A **piecewise linear function** is something like:

```
f(x) = a⋅x+b for x <= p
c⋅x+d for x > p
```

There may be more segments.

You describe just an **OR** (not a piecewise linear function):

```
C[i,k] = PR[i]⋅HSE[k] OR 1
```

What you describe can be modeled with an extra **binary variable** `δ[i,k] ∈ {0,1}`

as:

```
C[i,k] = (PR[i]⋅HSE[k])⋅δ[i,k] + (1-δ[i,k])
```

This is linear, as PR and HSE are constants. I assume that `C`

is a decision variable.

- Ternary operator vs if statement: compiler optimization
- Rectangular Nesting - Convergence to optimal solution using Simulated Annealing
- How to produce codes that always trigger signal SIGFPE (div by zero)?
- Is there a runtime cost of assigning variables in Rust?
- Rounding up to next power of 2
- What's the fastest way to check if a list contains an item in Go?
- How can I optimize the algorithm to find the longest common subsequence (LCS) between two strings?
- SCIP - stuck in clique table clean up
- Is it legal for a C++ optimizer to reorder calls to clock()?
- For loop is slowing down performance. Any alternatives?
- Looking to identify a "classic" problem and identify availble algorithms to solve it
- Unity keeps crashing on while loop (C#) (simplex method program)
- How to calculate a Kernel/Matrix efficiently
- Android M startActivity battery optimization
- Is there a way to further optimize this code?
- Getting adjoint state of solution in Gekko
- HALO support on recent compilers for C++ coroutines
- Which is faster php date functions or carbon?
- How to perform raster calculation (e.g. aspect) on subset of raster based on point intersection in R
- Fastest implementation of sine, cosine and square root in C++ (doesn't need to be much accurate)
- Print All JVM Flags
- Travelling Salesman in scipy
- Hyperopt set timeouts and modify space during execution
- Slow treeview in C#
- Identifying specific items in a df list field to update other fields, at scale
- Generating constraints with conditional summing over several pyomo subsets
- Optimizing for loop for using dictionary values to format new fasta files
- Runtime error when trying to find components in a graph
- performance of log10 function returning an int
- Replace punctuation with whitespace