text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:2] <= 1)

                     @variable(m, -47.221875796417265 <= q <= 49.11122836315772)

                     add_NL_constraint(m, :(sigmoid(0.42790162605340454 + 0.9948146339173967*sigmoid(0.30429674417798 + 0.01326158862793747*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8506753528903843*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7699605184902198*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9481609482474158*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + 0.5690258167368487*sigmoid(0.4003333530904172 + 0.4565361301167439*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.41218949132242644*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6719961553691296*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9454422589116072*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.632632285898699*sigmoid(-0.4740061987673023 + -0.21503151130953757*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7641417558802628*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8796988576372375*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6466469730144713*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.0799939753544896*sigmoid(-0.9533597279323933 + 0.019939841305541606*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.8134733780415981*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.10348468441851777*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.008542712959329624*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))))) + sigmoid(-0.31282642357163937 + 0.400776902433146*sigmoid(0.30429674417798 + 0.01326158862793747*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8506753528903843*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7699605184902198*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9481609482474158*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.8700113611274283*sigmoid(0.4003333530904172 + 0.4565361301167439*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.41218949132242644*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6719961553691296*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9454422589116072*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.8173535730312884*sigmoid(-0.4740061987673023 + -0.21503151130953757*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7641417558802628*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8796988576372375*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6466469730144713*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.10383649475667989*sigmoid(-0.9533597279323933 + 0.019939841305541606*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.8134733780415981*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.10348468441851777*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.008542712959329624*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))))) + sigmoid(0.07748802701261592 + -0.48287575350847955*sigmoid(0.30429674417798 + 0.01326158862793747*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8506753528903843*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7699605184902198*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9481609482474158*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + 0.9032398979921337*sigmoid(0.4003333530904172 + 0.4565361301167439*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.41218949132242644*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6719961553691296*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9454422589116072*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + 0.8154202752057489*sigmoid(-0.4740061987673023 + -0.21503151130953757*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7641417558802628*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8796988576372375*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6466469730144713*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + 0.8885160528665201*sigmoid(-0.9533597279323933 + 0.019939841305541606*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.8134733780415981*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.10348468441851777*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.008542712959329624*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))))) + sigmoid(0.6389491685818425 + -0.9024035564379238*sigmoid(0.30429674417798 + 0.01326158862793747*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8506753528903843*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7699605184902198*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9481609482474158*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.8688708754259227*sigmoid(0.4003333530904172 + 0.4565361301167439*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.41218949132242644*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6719961553691296*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.9454422589116072*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + -0.9399903753655909*sigmoid(-0.4740061987673023 + -0.21503151130953757*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.7641417558802628*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.8796988576372375*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.6466469730144713*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2])))) + 0.5656846187923494*sigmoid(-0.9533597279323933 + 0.019939841305541606*sigmoid(0.7020479917236249 + 0.5157446936496526*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.8162922098274223*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6507571114046486*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + 0.3903970834590602*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.8134733780415981*sigmoid(0.7594455380381384 + 0.9088497207479063*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + 0.34867162336420376*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + -0.586942758624089*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.05285512797069236*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + -0.10348468441851777*sigmoid(0.5333438081093944 + -0.9884706408297048*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.9213430875393112*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.6584439947423988*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.39397409418232554*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))) + 0.008542712959329624*sigmoid(-0.8688273038537231 + -0.5762764679031651*sigmoid(-0.990780872931377 + 0.7098282678057655*$(x[1]) + -0.9123645360112271*$(x[2])) + -0.4115583086286181*sigmoid(-0.26001558800187974 + -0.2578347550825866*$(x[1]) + -0.8440952761970419*$(x[2])) + 0.07598378122288318*sigmoid(0.6359235954642828 + 0.0835591752979501*$(x[1]) + -0.4064923799931912*$(x[2])) + -0.5005567670062852*sigmoid(0.919513762198326 + -0.48206842436164976*$(x[1]) + 0.2512150299638187*$(x[2]))))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
require("Color")
require("Iterators")
require("JSON")

module Compose

using Color
using Iterators
using DataStructures
using Compat
import JSON

import Base: length, start, next, done, isempty, getindex, setindex!,
             display, writemime, convert, zero, isless, max, fill, size, copy,
             min, max, +, -, *, /

export compose, compose!, Context, UnitBox, AbsoluteBoundingBox, Rotation, Mirror,
       ParentDrawContext, context, ctxpromise, table, set_units!, minwidth, minheight,
       text_extents, max_text_extents, polygon, line, rectangle, circle, path,
       ellipse, text, curve, bitmap, stroke, fill, strokedash, strokelinecap,
       strokelinejoin, linewidth, visible, fillopacity, strokeopacity, clip,
       font, fontsize, svgid, svgclass, svgattribute, jsinclude, jscall, Measure,
       inch, mm, cm, pt, px, cx, cy, w, h, hleft, hcenter, hright, vtop, vcenter,
       vbottom, SVG, SVGJS, PGF, PNG, PS, PDF, draw, pad, pad_inner, pad_outer,
       hstack, vstack, gridstack, LineCapButt, LineCapSquare, LineCapRound,
       CAIROSURFACE, introspect, set_default_graphic_size, set_default_jsmode,
       boundingbox, Patchable

abstract Backend

function isinstalled(pkg, ge=v"0.0.0")
    try
        # Pkg.installed might throw an error,
        # we need to account for it to be able to precompile
        ver = Pkg.installed(pkg)
        if ver != nothing && ver >= ge
            return true
        else
            return false
        end
    catch
        return false
    end
end

include("misc.jl")
include("measure.jl")
include("list.jl")

# Every graphic in Compose consists of a tree.
abstract ComposeNode

# Used to mark null child pointers
immutable NullNode <: ComposeNode end
nullnode = NullNode()

include("form.jl")
include("property.jl")
include("container.jl")
include("table.jl")
include("stack.jl")

# How large to draw graphics when not explicitly drawing to a backend
default_graphic_width = sqrt(2)*10*cm
default_graphic_height = 10cm

function set_default_graphic_size(width::MeasureOrNumber,
                                  height::MeasureOrNumber)
    global default_graphic_width
    global default_graphic_height
    default_graphic_width = x_measure(width)
    default_graphic_height = y_measure(height)
    nothing
end

default_graphic_format = :html

function set_default_graphic_format(fmt::Symbol)
    if !(fmt in [:html, :png, :svg, :pdf, :ps, :pgf])
        error("$(fmt) is not a supported plot format")
    end
    global default_graphic_format
    default_graphic_format = fmt
    nothing
end

# Default means to include javascript dependencies in the SVGJS backend.
default_jsmode = :embed

function set_default_jsmode(mode::Symbol)
    global default_jsmode
    if mode in [:none, :exclude, :embed, :linkabs, :linkrel]
        default_jsmode = mode
    else
        error("$(mode) is not a valid jsmode")
    end
    nothing
end

function default_mime()
    if default_graphic_format == :png
        "image/png"
    elseif default_graphic_format == :svg
        "image/svg+xml"
    elseif default_graphic_format == :html
        "text/html"
    elseif default_graphic_format == :ps
        "application/postscript"
    elseif default_graphic_format == :pdf
        "application/pdf"
    elseif default_graphic_format == :pgf
        "application/x-tex"
    else
        ""
    end
end

# Default property values
default_font_family = "Helvetica Neue,Helvetica,Arial,sans"
default_font_size = 11pt
default_line_width = 0.3mm
default_stroke_color = nothing
default_fill_color = color("black")

# Use cairo for the PNG, PS, PDF if its installed.
try
    require("Cairo")
    include("cairo_backends.jl")
catch
    global PNG
    global PS
    global PDF
    PNG(::Union(IO,String), ::MeasureOrNumber, ::MeasureOrNumber) =
        error("Cairo must be installed to use the PNG backend.")
    PS(::Union(IO,String), ::MeasureOrNumber, ::MeasureOrNumber) =
        error("Cairo must be installed to use the PS backend.")
    PDF(::Union(IO,String), ::MeasureOrNumber, ::MeasureOrNumber) =
        error("Cairo must be installed to use the PDF backend.")
end
include("svg.jl")
include("pgf_backend.jl")

if isinstalled("Patchwork", v"0.1.2")
    include("patchwork.jl")
end

# If available, pango and fontconfig are used to compute text extents and match
# fonts. Otherwise a simplistic pure-julia fallback is used.

try
    # Trigger an exception if unavailable.
    require("Fontconfig")

    pango_cairo_ctx = C_NULL
    include("pango.jl")

    function __init__()
        global pango_cairo_ctx
        global pangolayout
        ccall((:g_type_init, Cairo._jl_libgobject), Void, ())
        pango_cairo_fm  = ccall((:pango_cairo_font_map_new, libpangocairo),
                                 Ptr{Void}, ())
        pango_cairo_ctx = ccall((:pango_font_map_create_context, libpango),
                                 Ptr{Void}, (Ptr{Void},), pango_cairo_fm)
        pangolayout = PangoLayout()
    end
catch
    include("fontfallback.jl")
end

function writemime(io::IO, m::MIME"text/html", ctx::Context)
    draw(SVGJS(io, default_graphic_width, default_graphic_height, false,
               jsmode=default_jsmode), ctx)
end

function writemime(io::IO, m::MIME"image/svg+xml", ctx::Context)
    draw(SVG(io, default_graphic_width, default_graphic_height, false), ctx)
end

try
    getfield(Compose, :Cairo) # throws if Cairo isn't being used
    function writemime(io::IO, ::MIME"image/png", ctx::Context)
        draw(PNG(io, default_graphic_width, default_graphic_height), ctx)
    end
end

import Base.Multimedia: @try_display, xdisplayable

function display(p::Context)
    displays = Base.Multimedia.displays
    for i = length(displays):-1:1
        m = default_mime()
        if xdisplayable(displays[i], m, p)
             @try_display return display(displays[i], m, p)
        end

        if xdisplayable(displays[i], p)
            @try_display return display(displays[i], p)
        end
    end
    invoke(display,(Any,),p)
end

function pad_outer(c::Context,
                   left_padding::MeasureOrNumber,
                   right_padding::MeasureOrNumber,
                   top_padding::MeasureOrNumber,
                   bottom_padding::MeasureOrNumber)

    left_padding   = size_measure(left_padding)
    right_padding  = size_measure(right_padding)
    top_padding    = size_measure(top_padding)
    bottom_padding = size_measure(bottom_padding)

    root = context(c.box.x0, c.box.y0,
                   c.box.width + left_padding + right_padding,
                   c.box.height + top_padding + bottom_padding,
                   minwidth=c.minwidth,
                   minheight=c.minheight)
    c = copy(c)
    c.box = BoundingBox(left_padding, top_padding,
                        1w - left_padding - right_padding,
                        1h - top_padding - bottom_padding)
    return compose!(root, c)
end

function pad_outer(c::Context, padding::MeasureOrNumber)
    return pad_outer(c, padding, padding, padding, padding)
end

function pad_outer(cs::Vector{Context},
                   left_padding::MeasureOrNumber,
                   right_padding::MeasureOrNumber,
                   top_padding::MeasureOrNumber,
                   bottom_padding::MeasureOrNumber)
    return map(c -> pad_outer(c, left_padding, right_padding,
                              top_padding, bottom_padding), cs)
end

function pad_outer(cs::Vector{Context}, padding::MeasureOrNumber)
    return pad_outer(cs, padding, padding, padding, padding)
end

function pad_inner(c::Context,
                   left_padding::MeasureOrNumber,
                   right_padding::MeasureOrNumber,
                   top_padding::MeasureOrNumber,
                   bottom_padding::MeasureOrNumber)
    left_padding   = size_measure(left_padding)
    right_padding  = size_measure(right_padding)
    top_padding    = size_measure(top_padding)
    bottom_padding = size_measure(bottom_padding)

    root = context(c.box.x0, c.box.y0,
                   c.box.width,
                   c.box.height,
                   minwidth=c.minwidth,
                   minheight=c.minheight)
    c = copy(c)
    c.box = BoundingBox(left_padding, top_padding,
                        1w - left_padding - right_padding,
                        1h - top_padding - bottom_padding)
    return compose!(root, c)
end

function pad_inner(c::Context, padding::MeasureOrNumber)
    return pad_inner(c, padding, padding, padding, padding)
end

function pad_inner(cs::Vector{Context}, left_padding::MeasureOrNumber,
                   right_padding::MeasureOrNumber,
                   top_padding::MeasureOrNumber,
                   bottom_padding::MeasureOrNumber)
    return map(c -> pad_inner(c, left_padding, right_padding,
                              top_padding, bottom_padding), cs)
end

function pad_inner(cs::Vector{Context}, padding::MeasureOrNumber)
    return pad_inner(cs, padding, padding, padding, padding)
end

function gridstack(cs::Matrix{Context})
    m, n = size(cs)
    t = Table(m, n, 1:m, 1:n, x_prop=ones(n), y_prop=ones(m))
    for i in 1:m, j in 1:n
        t[i, j] = [cs[i, j]]
    end
    return compose!(context(), t)
end

const pad = pad_outer

end # module Compose

ext: jl


text:
using Multilane
using StatsBase
using MCTS
using JLD
using POMDPToolbox
using POMDPs
# using POMCP

using Gallium

dpws = DPWSolver(depth=20,
                 # n_iterations=500,
                 max_time=1.0,
                 exploration_constant=50.0,
                 k_state=4.0,
                 alpha_state=1/8,
                 estimate_value=RolloutEstimator(SimpleSolver()))

solver = SingleBehaviorSolver(dpws, Multilane.NORMAL)

lambda = 10.0
behaviors = standard_uniform(correlation=0.75)
pp = PhysicalParam(4, lane_length=100.0)
dmodel = NoCrashIDMMOBILModel(10, pp,
                              behaviors=behaviors,
                              p_appear=1.0,
                              lane_terminate=false)
rmodel = NoCrashRewardModel()
rmodel.brake_penalty_thresh = 4.0
rmodel.cost_dangerous_brake = lambda*rmodel.reward_in_target_lane
pomdp = NoCrashPOMDP{typeof(rmodel)}(dmodel, rmodel, 0.95)
mdp = NoCrashMDP{typeof(rmodel)}(dmodel, rmodel, 0.95)
is = initial_state(pomdp, Base.GLOBAL_RNG)
ips = MLPhysicalState(is)

planner = solve(solver, mdp)
agg_up = AggressivenessUpdater(pomdp, 500, 0.1, 0.1, WeightUpdateParams(smoothing=0.0, wrong_lane_factor=0.5), MersenneTwister(123))

for
    sims = [Sim(pomdp, planner, agg_up, ips, is, max_steps=100)]

end


text:
@testset "cat" begin
    a = [10 20; 31 40]
    nda = NamedDimsArray(a, (:x, :y))

    @testset "basic functionality" begin
        # check cat when NDAs are involved gives the same result as cat on arrays
        for d in 1:3
            @test cat(a; dims=d) ==
                  parent(cat(nda; dims=d))
            @test cat(a, a; dims=d) ==
                  parent(cat(nda, a; dims=d)) ==
                  parent(cat(a, nda; dims=d)) ==
                  parent(cat(nda, nda; dims=d))
            @test cat(a, a, a; dims=d) ==
                  parent(cat(a, nda, nda; dims=d)) ==
                  parent(cat(nda, a, nda; dims=d)) ==
                  parent(cat(nda, nda, nda; dims=d))
        end
    end

    @testset "dimensions requirements" begin
        # check that conflicting dimensions are flagged as errors
        for d in 1:3
            @test_throws DimensionMismatch cat(nda, nda'; dims=d)
            @test_throws DimensionMismatch cat(nda, nda, nda'; dims=d)
            @test_throws DimensionMismatch cat(a, nda, nda'; dims=d)
            @test_skip @test_throws DimensionMismatch cat(a, a, nda, nda'; dims=d)
        end

        # check that dimnames work as expected (for one, two, three args)
        for d in 1:2
            @test dimnames(cat(nda; dims=d)) == dimnames(nda)

            @test dimnames(cat(nda, nda; dims=d)) == dimnames(nda)
            @test dimnames(cat(nda, a; dims=d)) == dimnames(nda)
            @test dimnames(cat(a, nda; dims=d)) == dimnames(nda)

            @test dimnames(cat(nda, nda, nda; dims=d)) == dimnames(nda)
            @test dimnames(cat(a, nda, nda; dims=d)) == dimnames(nda)
            @test dimnames(cat(nda, a, nda; dims=d)) == dimnames(nda)
        end

        # and the same thing for dims=3
        @test dimnames(cat(nda; dims=3)) == (dimnames(nda)..., :_)

        @test dimnames(cat(nda, nda; dims=3)) == (dimnames(nda)..., :_)
        @test dimnames(cat(nda, a; dims=3)) == (dimnames(nda)..., :_)
        @test dimnames(cat(a, nda; dims=3)) == (dimnames(nda)..., :_)

        @test dimnames(cat(nda, nda, nda; dims=3)) == (dimnames(nda)..., :_)
        @test dimnames(cat(a, nda, nda; dims=3)) == (dimnames(nda)..., :_)
        @test dimnames(cat(nda, a, nda; dims=3)) == (dimnames(nda)..., :_)
    end

    # check dims::Symbol cases
    @testset "dims argument is named" begin
        @test cat(nda, nda; dims=1) == cat(nda, nda; dims=:x)
        @test cat(nda, nda; dims=2) == cat(nda, nda; dims=:y)

        @test dimnames(cat(nda, nda; dims=:z)) == (:x, :y, :z)
    end
end

for (f, d) in zip((vcat, hcat), (1, 2))
    a = [10 20; 31 40]
    nda = NamedDimsArray(a, (:x, :y))
    v = [1, 2, 3, 4]
    ndv = NamedDimsArray(v, (:x, ))

    @testset "$f" begin
        @testset "basic functionality" begin
            @test f(nda) == cat(nda; dims=d)
            @test f(ndv) == cat(ndv; dims=d)

            @test f(nda, nda) == cat(nda, nda; dims=d)
            @test f(a, nda) == cat(a, nda; dims=d)
            @test f(nda, a) == cat(nda, a; dims=d)

            @test f(nda, nda, nda) == cat(nda, nda, nda; dims=d)
            @test f(a, nda, nda) == cat(a, nda, nda; dims=d)
            @test f(nda, a, nda) == cat(nda, a, nda; dims=d)
            @test f(nda, nda, a) == cat(nda, nda, a; dims=d)
        end

        @testset "dimension requirements" begin
            @test_throws DimensionMismatch f(nda, nda')
            @test_throws DimensionMismatch f(nda, nda, nda')

            @test dimnames(f(nda)) == dimnames(cat(nda; dims=d))
            @test dimnames(f(ndv)) == dimnames(cat(ndv; dims=d))

            @test dimnames(f(nda, nda)) == dimnames(cat(nda, nda; dims=d))
            @test dimnames(f(nda, a)) == dimnames(cat(nda, a; dims=d))
            @test dimnames(f(a, nda)) == dimnames(cat(a, nda; dims=d))
        end

        @testset "reduce forms" begin
            @test reduce(f, [nda, nda]) == f(nda, nda)
            @test reduce(f, [ndv, ndv]) == f(ndv, ndv)

            v1 = NamedDimsArray([a, a], dimnames(nda, d))
            v2 = NamedDimsArray([a, nda, a, nda], dimnames(nda, d))
            @test dimnames(reduce(f, v1), d) == dimnames(nda, d)
            @test dimnames(reduce(f, v2)) == dimnames(nda)

            v3 = NamedDimsArray([a, nda', a], dimnames(nda, d)) # inner mismatch outer
            @test_throws Exception reduce(f, v3)

            @test_throws Exception reduce(f, [nda, nda']) # inconsistent inner names
        end
    end
end

@testset "more cats" begin
    @testset "more than 2 dimensions" begin
        ndt = NamedDimsArray(rand(Int8,2,2,2), (:x, :y, :z))

        @test dimnames(hcat(ndt, ndt, parent(ndt))) == (:x, :y, :z)
        @test dimnames(cat(ndt, ndt, parent(ndt), dims=:y)) == (:x, :y, :z)

        @test_throws Exception hcat(ndt, parent(ndt), permutedims(ndt, (3,2,1)))
        @test_throws Exception cat(ndt, parent(ndt), permutedims(ndt, (3,2,1)), dims=2)

    end
    @testset "tricky cases" begin
        r23 = rand(Int8, 2,3)
        nda = NamedDimsArray(rand(2,3), (:x, :y))
        ndv = NamedDimsArray(rand(2), (:x,))

        @test dimnames(hcat(nda, ndv)) == (:x, :y)
        @test dimnames(cat(nda, ndv, dims=2)) == (:x, :y)
        @test dimnames(reduce(hcat, [nda, ndv])) == (:x, :y)

        @test dimnames(hcat(r23', nda', nda')) == (:y, :x)
        @test dimnames(cat(r23', nda', nda', dims=2)) == (:y, :x)

        @test_throws Exception hcat(nda, r23')
        @test_throws Exception cat(nda, r23', dims=2)

        @test size(cat(nda', r23', nda', dims=(:x, :y))) == (9,6)
        @test dimnames(cat(nda', r23', nda', dims=(1,2))) == (:y, :x)

        @test dimnames(cat(1:2, ndv, [5 6]', dims=:z)) == (:x, :_, :z)

        @test dimnames(vcat(1:3, NamedDimsArray(4:6, :x))) == (:x,)

        vcat(pi, ndv) # does not at present have names
        vcat(ndv, pi)
    end
end


text:
export asarray, asscalar

"""
    asarray(x[, parent::AbstractArray]) -> AbstactArray

Return a 0-dimensional array with item `x`, otherwise, do nothing.
If a `parent` is supplied, it will try to match the parent array type.
"""
asarray(x) = fill(x, ())
asarray(x::AbstractArray) = x
asarray(x, arr::AbstractArray) = fill(x, ())
asarray(x::AbstractArray, y::Array) = x
asscalar(x) = x
asscalar(x::AbstractArray) = x[]
_collect(x) = collect(x)
_collect(x::Vector) = x
_collect(::Type{T}, x::Vector{T}) where T = x
_collect(::Type{T}, x) where T = collect(T, x)
_insertat(lst::Tuple, i, item) = TupleTools.insertat(lst, i, (item,))
_insertat(lst::AbstractVector, i, item) = (lst=copy(lst); lst[i]=item; lst)

"""
    nopermute(ix,iy)

check that all values in `iy` that are also in `ix` have the same relative order,

# example

```jldoctest; setup = :(using OMEinsum)
julia> using OMEinsum: nopermute

julia> nopermute((1,2,3),(1,2))
true

julia> nopermute((1,2,3),(2,1))
false
```
e.g. `nopermute((1,2,3),(1,2))` is true while `nopermute((1,2,3),(2,1))` is false
"""
function nopermute(ix::NTuple, iy::NTuple)
    i, j, jold = 1, 1, 0
    # find each element of iy in ix and check that the order is the same
    for i in 1:length(iy)
        j = findfirst(==(iy[i]), ix)
        (j === nothing || j <= jold) && return false
        jold = j
    end
    return true
end

"""
    allunique(ix::Tuple)

return true if all elements of `ix` appear only once in `ix`.

# example

```jldoctest; setup = :(using OMEinsum)
julia> using OMEinsum: allunique

julia> allunique((1,2,3,4))
true

julia> allunique((1,2,3,1))
false
```
"""
allunique(ix) = all(i -> count(==(i), ix) == 1, ix)
_unique(::Type{T}, x::NTuple{N,T}) where {N,T} = unique!(collect(T, x))
_unique(::Type{T}, x::Vector{T}) where T = unique(x)

function align_eltypes(xs::AbstractArray...)
    T = promote_type(eltype.(xs)...)
    return map(x->eltype(x)==T ? x : T.(x), xs)
end

function align_eltypes(xs::AbstractArray{T}...) where T
    xs
end

"""
    tensorpermute(A, perm)

Aliasing `permutedims(A, perm)`.
"""
tensorpermute(A::AbstractArray, perm) = length(perm) == 0 ? copy(A) : permutedims(A, perm)

# reload this function for GPU support!
function _batched_gemm(C1::Char, C2::Char, A::StridedArray{T,3}, B::StridedArray{T2,3}) where {T<:BlasFloat, T2<:BlasFloat}
    batched_gemm(C1, C2, A, B)
end

function _batched_gemm(C1::Char, C2::Char, A::AbstractArray{T,3}, B::AbstractArray{T2,3}) where {T<:BlasFloat, T2<:BlasFloat}
    batched_gemm(C1, C2, Array(A), Array(B))
end

function _batched_gemm(C1::Char, C2::Char, A::AbstractArray{T,3}, B::AbstractArray{T2,3}) where {T, T2}
    @assert size(A, 3) == size(B, 3) "batch dimension mismatch, got $(size(A,3)) and $(size(B,3))"
    @assert C1 === 'N' || C1 === 'T'
    @assert C2 === 'N' || C2 === 'T'
    L = size(A, 3)
    C = similar(A, promote_type(T,T2), C1==='N' ? size(A,1) : size(A,2), C2==='N' ? size(B,2) : size(B,1), L)
    for l = 1:L
        a = C1 === 'T' ? transpose(view(A,:,:,l)) : view(A,:,:,l)
        b = C2 === 'T' ? transpose(view(B,:,:,l)) : view(B,:,:,l)
        mul!(view(C,:,:,l), a, b)
    end
    return C
end


text:
@testset "validations" begin
  using LightGraphs
  ij = kronecker_generator(2,2;replicate=true,seed=[10,4,78,12,5,72])
  g = kernel_1(ij)
  parent_ = kernel_2(g,0x01)

  # check that parent of search key is itself
  parent_[1] = 0x05
  @test validate(g,parent_,ij,0x01) == 0

  # check for cycle
  g = Graph(4)
  ij = [1 2 2 3; 2 3 4 4]
  parent_ = [1,4,3,2]
  @test validate(g,parent_,ij,1) == -3

  # check for connected component
  parent_ = [1,1,2,0]
  @test validate(g,parent_,ij,1) == -4

  # check for bfs levels
  parent_ = [1,1,4,2]
  @test validate(g,parent_,ij,1) == -5
end


text:
# joRomberg operator

## helper module
module joRomberg_etc
    using JOLI: jo_convert, jo_complex_eltype, LocalVector
    using FFTW

    function random_phases(DT::DataType,dims::Dims)
        dt = DT<:Complex ? jo_complex_eltype(DT) : DT
        p1 = exp.((dt(2)*im*pi).*rand(dt,dims))
        p2 = fft(real(ifft(p1)));
        p = p2./abs.(p2)
    end

    function apply_fwd(dims::Dims,phs::Array,sgn::Array,v::LocalVector{VT},rdt::DataType) where VT<:Real
       a = reshape(v,dims)
       y = real(sgn.*ifft(phs.*fft(a)))
       return jo_convert(rdt,vec(y),false)
    end
    function apply_fwd(dims::Dims,phs::Array,sgn::Array,v::LocalVector{VT},rdt::DataType) where VT<:Complex
       a = reshape(v,dims)
       y = sgn.*ifft(phs.*fft(a))
       return jo_convert(rdt,vec(y),false)
    end

    function apply_adj(dims::Dims,phs::Array,sgn::Array,v::LocalVector{VT},rdt::DataType) where VT<:Real
       a = reshape(v,dims)
       y = real(ifft(conj(phs).*fft(sgn.*a)))
       return jo_convert(rdt,vec(y),false)
    end
    function apply_adj(dims::Dims,phs::Array,sgn::Array,v::LocalVector{VT},rdt::DataType) where VT<:Complex
       a = reshape(v,dims)
       y = ifft(conj(phs).*fft(sgn.*a))
       return jo_convert(rdt,vec(y),false)
    end

end
using .joRomberg_etc

export joRomberg
"""
    julia> op = joRomberg(n1[,n2[,...]];[DDT=...,][RDT=...,][name=...])

A random comvolution based on Romberg 08

# Signature

    joRomberg(dims::Integer...;
        DDT::DataType=joFloat,RDT::DataType=DDT,name::String="joRomberg")

# Arguments

- `n1[,n2[...]]`: dimensions of the image; M=N=prod(ni)
- keywords
    - `DDT`: domain data type
    - `RDT`: range data type
    - `name`: custom name

# Examples

    A=joRomberg(9)
    A=joRomberg(9,11)

examples with DDT/RDT

    A=joRomberg(9,11; DDT=Float32)
    A=joRomberg(9,11; DDT=Float32,RDT=Float64)

"""
function joRomberg(dims::Integer...;DDT::DataType=joFloat,RDT::DataType=DDT,name::String="joRomberg")

    m = n = prod(dims)
    phs = joRomberg_etc.random_phases(DDT,dims)
    sgn = sign.(randn(dims))
    return joLinearFunctionFwd_A(m,n,
        v1->joRomberg_etc.apply_fwd(dims,phs,sgn,v1,RDT),
        v2->joRomberg_etc.apply_adj(dims,phs,sgn,v2,DDT),
        DDT,RDT;
        name=name)
end


text:
# This file is auto-generated by AWSMetadata.jl
using AWS
using AWS.AWSServices: cloud9
using AWS.Compat
using AWS.UUIDs

"""
    create_environment_ec2(instance_type, name)
    create_environment_ec2(instance_type, name, params::Dict{String,<:Any})

Creates an AWS Cloud9 development environment, launches an Amazon Elastic Compute Cloud
(Amazon EC2) instance, and then connects from the instance to the environment.

# Arguments
- `instance_type`: The type of instance to connect to the environment (for example,
  t2.micro).
- `name`: The name of the environment to create. This name is visible to other AWS IAM
  users in the same AWS account.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"automaticStopTimeMinutes"`: The number of minutes until the running instance is shut
  down after the environment has last been used.
- `"clientRequestToken"`: A unique, case-sensitive string that helps AWS Cloud9 to ensure
  this operation completes no more than one time. For more information, see Client Tokens in
  the Amazon EC2 API Reference.
- `"connectionType"`: The connection type used for connecting to an Amazon EC2 environment.
  Valid values are CONNECT_SSH (default) and CONNECT_SSM (connected through AWS Systems
  Manager). For more information, see Accessing no-ingress EC2 instances with AWS Systems
  Manager in the AWS Cloud9 User Guide.
- `"description"`: The description of the environment to create.
- `"imageId"`: The identifier for the Amazon Machine Image (AMI) that's used to create the
  EC2 instance. To choose an AMI for the instance, you must specify a valid AMI alias or a
  valid AWS Systems Manager (SSM) path. The default AMI is used if the parameter isn't
  explicitly assigned a value in the request.   AMI aliases      Amazon Linux (default):
  amazonlinux-1-x86_64     Amazon Linux 2: amazonlinux-2-x86_64    Ubuntu 18.04:
  ubuntu-18.04-x86_64     SSM paths     Amazon Linux (default):
  resolve:ssm:/aws/service/cloud9/amis/amazonlinux-1-x86_64     Amazon Linux 2:
  resolve:ssm:/aws/service/cloud9/amis/amazonlinux-2-x86_64    Ubuntu 18.04:
  resolve:ssm:/aws/service/cloud9/amis/ubuntu-18.04-x86_64
- `"ownerArn"`: The Amazon Resource Name (ARN) of the environment owner. This ARN can be
  the ARN of any AWS IAM principal. If this value is not specified, the ARN defaults to this
  environment's creator.
- `"subnetId"`: The ID of the subnet in Amazon VPC that AWS Cloud9 will use to communicate
  with the Amazon EC2 instance.
- `"tags"`: An array of key-value pairs that will be associated with the new AWS Cloud9
  development environment.
"""
create_environment_ec2(instanceType, name; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("CreateEnvironmentEC2", Dict{String, Any}("instanceType"=>instanceType, "name"=>name); aws_config=aws_config)
create_environment_ec2(instanceType, name, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("CreateEnvironmentEC2", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("instanceType"=>instanceType, "name"=>name), params)); aws_config=aws_config)

"""
    create_environment_membership(environment_id, permissions, user_arn)
    create_environment_membership(environment_id, permissions, user_arn, params::Dict{String,<:Any})

Adds an environment member to an AWS Cloud9 development environment.

# Arguments
- `environment_id`: The ID of the environment that contains the environment member you want
  to add.
- `permissions`: The type of environment member permissions you want to associate with this
  environment member. Available values include:    read-only: Has read-only access to the
  environment.    read-write: Has read-write access to the environment.
- `user_arn`: The Amazon Resource Name (ARN) of the environment member you want to add.

"""
create_environment_membership(environmentId, permissions, userArn; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("CreateEnvironmentMembership", Dict{String, Any}("environmentId"=>environmentId, "permissions"=>permissions, "userArn"=>userArn); aws_config=aws_config)
create_environment_membership(environmentId, permissions, userArn, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("CreateEnvironmentMembership", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentId"=>environmentId, "permissions"=>permissions, "userArn"=>userArn), params)); aws_config=aws_config)

"""
    delete_environment(environment_id)
    delete_environment(environment_id, params::Dict{String,<:Any})

Deletes an AWS Cloud9 development environment. If an Amazon EC2 instance is connected to
the environment, also terminates the instance.

# Arguments
- `environment_id`: The ID of the environment to delete.

"""
delete_environment(environmentId; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DeleteEnvironment", Dict{String, Any}("environmentId"=>environmentId); aws_config=aws_config)
delete_environment(environmentId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DeleteEnvironment", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentId"=>environmentId), params)); aws_config=aws_config)

"""
    delete_environment_membership(environment_id, user_arn)
    delete_environment_membership(environment_id, user_arn, params::Dict{String,<:Any})

Deletes an environment member from an AWS Cloud9 development environment.

# Arguments
- `environment_id`: The ID of the environment to delete the environment member from.
- `user_arn`: The Amazon Resource Name (ARN) of the environment member to delete from the
  environment.

"""
delete_environment_membership(environmentId, userArn; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DeleteEnvironmentMembership", Dict{String, Any}("environmentId"=>environmentId, "userArn"=>userArn); aws_config=aws_config)
delete_environment_membership(environmentId, userArn, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DeleteEnvironmentMembership", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentId"=>environmentId, "userArn"=>userArn), params)); aws_config=aws_config)

"""
    describe_environment_memberships()
    describe_environment_memberships(params::Dict{String,<:Any})

Gets information about environment members for an AWS Cloud9 development environment.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"environmentId"`: The ID of the environment to get environment member information about.
- `"maxResults"`: The maximum number of environment members to get information about.
- `"nextToken"`: During a previous call, if there are more than 25 items in the list, only
  the first 25 items are returned, along with a unique string called a next token. To get the
  next batch of items in the list, call this operation again, adding the next token to the
  call. To get all of the items in the list, keep calling this operation with each subsequent
  next token that is returned, until no more next tokens are returned.
- `"permissions"`: The type of environment member permissions to get information about.
  Available values include:    owner: Owns the environment.    read-only: Has read-only
  access to the environment.    read-write: Has read-write access to the environment.   If no
  value is specified, information about all environment members are returned.
- `"userArn"`: The Amazon Resource Name (ARN) of an individual environment member to get
  information about. If no value is specified, information about all environment members are
  returned.
"""
describe_environment_memberships(; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DescribeEnvironmentMemberships"; aws_config=aws_config)
describe_environment_memberships(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DescribeEnvironmentMemberships", params; aws_config=aws_config)

"""
    describe_environment_status(environment_id)
    describe_environment_status(environment_id, params::Dict{String,<:Any})

Gets status information for an AWS Cloud9 development environment.

# Arguments
- `environment_id`: The ID of the environment to get status information about.

"""
describe_environment_status(environmentId; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DescribeEnvironmentStatus", Dict{String, Any}("environmentId"=>environmentId); aws_config=aws_config)
describe_environment_status(environmentId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DescribeEnvironmentStatus", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentId"=>environmentId), params)); aws_config=aws_config)

"""
    describe_environments(environment_ids)
    describe_environments(environment_ids, params::Dict{String,<:Any})

Gets information about AWS Cloud9 development environments.

# Arguments
- `environment_ids`: The IDs of individual environments to get information about.

"""
describe_environments(environmentIds; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DescribeEnvironments", Dict{String, Any}("environmentIds"=>environmentIds); aws_config=aws_config)
describe_environments(environmentIds, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("DescribeEnvironments", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentIds"=>environmentIds), params)); aws_config=aws_config)

"""
    list_environments()
    list_environments(params::Dict{String,<:Any})

Gets a list of AWS Cloud9 development environment identifiers.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"maxResults"`: The maximum number of environments to get identifiers for.
- `"nextToken"`: During a previous call, if there are more than 25 items in the list, only
  the first 25 items are returned, along with a unique string called a next token. To get the
  next batch of items in the list, call this operation again, adding the next token to the
  call. To get all of the items in the list, keep calling this operation with each subsequent
  next token that is returned, until no more next tokens are returned.
"""
list_environments(; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("ListEnvironments"; aws_config=aws_config)
list_environments(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("ListEnvironments", params; aws_config=aws_config)

"""
    list_tags_for_resource(resource_arn)
    list_tags_for_resource(resource_arn, params::Dict{String,<:Any})

Gets a list of the tags associated with an AWS Cloud9 development environment.

# Arguments
- `resource_arn`: The Amazon Resource Name (ARN) of the AWS Cloud9 development environment
  to get the tags for.

"""
list_tags_for_resource(ResourceARN; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("ListTagsForResource", Dict{String, Any}("ResourceARN"=>ResourceARN); aws_config=aws_config)
list_tags_for_resource(ResourceARN, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("ListTagsForResource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("ResourceARN"=>ResourceARN), params)); aws_config=aws_config)

"""
    tag_resource(resource_arn, tags)
    tag_resource(resource_arn, tags, params::Dict{String,<:Any})

Adds tags to an AWS Cloud9 development environment.  Tags that you add to an AWS Cloud9
environment by using this method will NOT be automatically propagated to underlying
resources.

# Arguments
- `resource_arn`: The Amazon Resource Name (ARN) of the AWS Cloud9 development environment
  to add tags to.
- `tags`: The list of tags to add to the given AWS Cloud9 development environment.

"""
tag_resource(ResourceARN, Tags; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("TagResource", Dict{String, Any}("ResourceARN"=>ResourceARN, "Tags"=>Tags); aws_config=aws_config)
tag_resource(ResourceARN, Tags, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("TagResource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("ResourceARN"=>ResourceARN, "Tags"=>Tags), params)); aws_config=aws_config)

"""
    untag_resource(resource_arn, tag_keys)
    untag_resource(resource_arn, tag_keys, params::Dict{String,<:Any})

Removes tags from an AWS Cloud9 development environment.

# Arguments
- `resource_arn`: The Amazon Resource Name (ARN) of the AWS Cloud9 development environment
  to remove tags from.
- `tag_keys`: The tag names of the tags to remove from the given AWS Cloud9 development
  environment.

"""
untag_resource(ResourceARN, TagKeys; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("UntagResource", Dict{String, Any}("ResourceARN"=>ResourceARN, "TagKeys"=>TagKeys); aws_config=aws_config)
untag_resource(ResourceARN, TagKeys, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("UntagResource", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("ResourceARN"=>ResourceARN, "TagKeys"=>TagKeys), params)); aws_config=aws_config)

"""
    update_environment(environment_id)
    update_environment(environment_id, params::Dict{String,<:Any})

Changes the settings of an existing AWS Cloud9 development environment.

# Arguments
- `environment_id`: The ID of the environment to change settings.

# Optional Parameters
Optional parameters can be passed as a `params::Dict{String,<:Any}`. Valid keys are:
- `"description"`: Any new or replacement description for the environment.
- `"name"`: A replacement name for the environment.
"""
update_environment(environmentId; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("UpdateEnvironment", Dict{String, Any}("environmentId"=>environmentId); aws_config=aws_config)
update_environment(environmentId, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("UpdateEnvironment", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentId"=>environmentId), params)); aws_config=aws_config)

"""
    update_environment_membership(environment_id, permissions, user_arn)
    update_environment_membership(environment_id, permissions, user_arn, params::Dict{String,<:Any})

Changes the settings of an existing environment member for an AWS Cloud9 development
environment.

# Arguments
- `environment_id`: The ID of the environment for the environment member whose settings you
  want to change.
- `permissions`: The replacement type of environment member permissions you want to
  associate with this environment member. Available values include:    read-only: Has
  read-only access to the environment.    read-write: Has read-write access to the
  environment.
- `user_arn`: The Amazon Resource Name (ARN) of the environment member whose settings you
  want to change.

"""
update_environment_membership(environmentId, permissions, userArn; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("UpdateEnvironmentMembership", Dict{String, Any}("environmentId"=>environmentId, "permissions"=>permissions, "userArn"=>userArn); aws_config=aws_config)
update_environment_membership(environmentId, permissions, userArn, params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = cloud9("UpdateEnvironmentMembership", Dict{String, Any}(mergewith(_merge, Dict{String, Any}("environmentId"=>environmentId, "permissions"=>permissions, "userArn"=>userArn), params)); aws_config=aws_config)


text:
# Sequence-form integrated cyber air defense, G = (N, Σ, g, C)
using Pkg; Pkg.activate(pwd())
using Revise, LinearAlgebra, FileIO, JLD2, ProgressMeter
using JuMP, Clp
using Clp: ClpCInterface

# load functions
dir = pwd()
include(joinpath(dir, "src\\ops_utility.jl"))
include(joinpath(dir, "src\\ops_build.jl"))
include(joinpath(dir, "src\\ops_methods.jl"))

#############
# best response
#############

# fix player 2's realization plan as uniformly random
# how to make better realization plan? Maybe pick a few pure strategies?
# greedy plan: defender assigns cyber assets to IADS with most covered value
function build_rp2(gos::GameOptSet)
    ns2, ns2_stage, na_stage = gos.ns2, gos.ns2_stage, gos.na_stage
    rp2 = zeros(Float64, ns2)
    ns_cumsum = cumsum(ns2_stage)
    p0 = 1.0
    p3 = p0 / na_stage[3]
    p6 = p3 / na_stage[6]
    rp2[1] = p0
    rp2[(ns_cumsum[1] + 1):ns_cumsum[2]] .= p3
    rp2[(ns_cumsum[2] + 1):ns_cumsum[3]] .= p6
    return rp2
end

function build_rp1(gos::GameOptSet)
    ns1, ns1_stage, na_stage = gos.ns1, gos.ns1_stage, gos.na_stage
    rp = zeros(Float64, ns1)
    ns_cumsum = cumsum(ns1_stage)
    p0 = 1.0
    p5 = p0 / na_stage[5]
    rp[1] = p0
    rp[(ns_cumsum[1] + 1):ns_cumsum[2]] .= p5
    return rp
end

function lp_best_response(gos::GameOptSet, rfixed::Vector{Float64}; fixedplayer::Int64 = 2)
    ns1, ns2, ni1, ni2, reward = gos.ns1, gos.ns2, gos.ni1, gos.ni2, gos.reward
    seqI1, seqI2, nextseqI1, nextseqI2 = gos.seqI1, gos.seqI2, gos.nextseqI1, gos.nextseqI2
    ind_nz = findall(!iszero, gos.reward)
    nsi, nso = fixedplayer == 1 ? (ns2, ns1) : (ns1, ns2)
    nii, nio = fixedplayer == 1 ? (ni2, ni1) : (ni1, ni2)
    seqIi, seqIo = fixedplayer == 1 ? (seqI2, seqI1) : (seqI1, seqI2)
    nextseqIi, nextseqIo = fixedplayer == 1 ? (nextseqI2, nextseqI1) : (nextseqI1, nextseqI2)
    println("Building model...")
    m = Model(Clp.Optimizer)
    @variable(m, r[1:nsi] >= 0)
    if fixedplayer == 1 # reward is player 1's reward(seq1, seq2) so we can't switch the indexes
        @objective(m, Max, sum(-1 * gos.reward[I] * rfixed[I[1]] * r[I[2]] for I in ind_nz))
    else
        @objective(m, Max, sum(gos.reward[I] * r[I[1]] * rfixed[I[2]] for I in ind_nz))
    end
    @constraint(m, r[1] == 1.0)
    # @progress for i in 1:nii
    for i in 1:nii
        @constraint(m, sum(r[si] for si in nextseqIi[i]) == r[seqIi[i]])
    end
    println("Solving model...")
    @show m
    status = solve(m)
    return status, getobjectivevalue(m), getvalue(r)
end

#############
# Nash Equilibrium
#############

# TODO: make building the objective function faster in lp_nash
function lp_nash(gos::GameOptSet; timelimit = 5 * 60)
    ns2, ni1, ni2, reward = gos.ns2, gos.ni1, gos.ni2, gos.reward
    ns1_stage, na_stage = gos.ns1_stage, gos.na_stage
    seqI2, nextseqI2 = gos.seqI2, gos.nextseqI2
    println("Building model...")
    mne = Model(solver = ClpSolver(MaximumSeconds = timelimit))
    @variable(mne, rp2[1:ns2] >= 0)
    @variable(mne, v1[1:ni1])
    @variable(mne, v0)
    @objective(mne, Min, v0)
    @constraint(mne, v0 - sum(v1[j] for j in 1:ni1) >= sum(reward[1, s2] * rp2[s2] for s2 in 1:ns2))
    nvconstraint = 1
    # @progress for s1 in (1 + 1):(1 + ns1_stage[2])
    for s1 in (1 + 1):(1 + ns1_stage[2])
        iind = ceil(Int, (s1 - 1) / na_stage[5]) # Σ1 is in blocks na_stage[5] actions for each infoset
        @constraint(mne, v1[iind] >= sum(reward[s1, s2] * rp2[s2] for s2 in 1:ns2))
        nvconstraint += 1
    end
    @constraint(mne, rp2[1] == 1)
    # @progress for i in 1:ni2
    for i in 1:ni2
        @constraint(mne, sum(rp2[s2] for s2 in nextseqI2[i]) == rp2[seqI2[i]])
    end
    @show mne
    println("Solving model...")
    status, t_solve = @timed solve(mne)
    println("obj value: $(getobjectivevalue(mne)), status: $status")
    rp1 = ClpCInterface.dual_row_solution(getrawsolver(mne))[1:nvconstraint] # player 1 strategy is the dual of player 1 values for each sequence constraint
    return status, getobjectivevalue(mne), rp1, getvalue(rp2), t_solve
end

#############
# Robust Best Response
#############

function lp_robust_br(gos::GameOptSet, rp2lb, rp2ub; timelimit = 5 * 60)
    ns2, ni1, ni2, reward = gos.ns2, gos.ni1, gos.ni2, gos.reward
    ns1_stage, na_stage = gos.ns1_stage, gos.na_stage
    seqI2, nextseqI2 = gos.seqI2, gos.nextseqI2
    println("Building model...")
    mr = Model(solver = ClpSolver(MaximumSeconds = timelimit))
    @variable(mr, rp2[1:ns2])
    @variable(mr, v1[1:ni1])
    @variable(mr, v0)
    @objective(mr, Min, v0)
    @constraint(mr, v0 - sum(v1[j] for j in 1:ni1) >= sum(reward[1, s2] * rp2[s2] for s2 in 1:ns2))
    # @progress for s1 in (1 + 1):(1 + ns1_stage[2])
    nvconstraint = 1
    for s1 in (1 + 1):(1 + ns1_stage[2])
        iind = ceil(Int, (s1 - 1) / na_stage[5]) # Σ1 is in blocks na_stage[5] actions for each infoset
        @constraint(mr, v1[iind] >= sum(reward[s1, s2] * rp2[s2] for s2 in 1:ns2))
        nvconstraint += 1
    end
    @constraint(mr, rp2[1] == 1)
    # @progress for i in 1:ni2
    for i in 1:ni2
        @constraint(mr, sum(rp2[s2] for s2 in nextseqI2[i]) == rp2[seqI2[i]])
    end
    @constraint(mr, rp2 .>= rp2lb)
    @constraint(mr, rp2 .<= rp2ub)
    @show mr
    println("Solving model...")
    status, t_solve = @timed solve(mr)
    rp1 = ClpCInterface.dual_row_solution(getrawsolver(mr))[1:nvconstraint] # player 1 strategy is the dual of player 1 values for each sequence constraint
    return status, getobjectivevalue(mr), rp1, getvalue(rp2), t_solve
end

max_stars_repo_name: ajkeith/Cyber-Air-Defense

max_issues_repo_name: ajkeith/Cyber-Air-Defense


text:
using DiffEqOperators
using StaticArrays

N = 10
deriv_order = 2
approx_order = 2
bound_order = 1

Q = Neumann0BC(1.0, bound_order)
D = CenteredDifference(deriv_order, approx_order, 1.0, N)
L = D*Q

conc = sparse(L)[1]

Ax = sparse(Tridiagonal([1.0 for i in 1:N-1],[-2.0 for i in 1:N],[1.0 for i in 1:N-1]))
Ax[2,1] = 2.0
Ax[end-1,end] = 2.0


text:
import Base
mutable struct Transpose <: DiffableFunction
    in_is_vector
    grad_field::GradField
    Transpose(in_shape, grad_field) = new(length(in_shape) == 1, grad_field)
end

function forward(::Transpose, x)
    return transpose(x)
end

function backward(f::Transpose, gy)
    gx = transpose(gy)
    (f.in_is_vector) && (return flatten(gx))
    return gx
end

"""
    transpose(x::Variable)
# Examples
```julia-repl
julia> x = Variable([1 2; 3 4])
name: nothing
values: [1 2; 3 4]
creator: User-Defined(nothing)

julia> transpose(x)
name: nothing
values: [1 3; 2 4]
creator: JITrench.Transpose
```
"""
Base.transpose(x::Variable) = Transpose(size(x.values), GradField())(x)
is_support(::typeof(Base.transpose)) = true


text:
using Adapt
using Statistics
using Oceananigans.Grids
using Oceananigans.Grids: interior_parent_indices

struct AveragedField{X, Y, Z, S, A, D, G, T, N, O} <: AbstractReducedField{X, Y, Z, A, G, T, N}
            data :: D
    architecture :: A
            grid :: G
            dims :: NTuple{N, Int}
         operand :: O
          status :: S

    function AveragedField{X, Y, Z}(data::D, arch::A, grid::G, dims, operand::O;
                                    recompute_safely=true) where {X, Y, Z, D, A, G, O}

        dims = validate_reduced_dims(dims)
        validate_reduced_locations(X, Y, Z, dims)
        validate_field_data(X, Y, Z, data, grid)

        status = recompute_safely ? nothing : FieldStatus(0.0)

        S = typeof(status)
        N = length(dims)
        T = eltype(grid)

        return new{X, Y, Z, S, A, D, G, T, N, O}(data, arch, grid, dims, operand, status)
    end

    function AveragedField{X, Y, Z}(data::D, arch::A, grid::G, dims, operand::O, status::S) where {X, Y, Z, D, A, G, O, S}
        return new{X, Y, Z, S, A, D, G, eltype(grid), length(dims), O}(data, arch, grid, dims, operand, status)
    end
end

"""
    AveragedField(operand::AbstractField; dims, data=nothing, recompute_safely=false)

Returns an AveragedField averaged over `dims`. `dims` is a tuple of integers indicating
spatial dimensions; in a Cartesian coordinate system, `1=x, `2=y`, and `3=z`.

Arguments
=========

- `dims`: Tuple of integers specifying the dimensions to average `operand`.
          A single integer is also accepted for averaging over a single dimension.

- `data`: An `OffsetArray` for storing averaged data.
          Useful if carefully managing memory allocation.
          If unspecified, `data` is created by `Oceananigans.Grids.new_data`.

- `recompute_safely`: A boolean that's relevant only if the `AveragedField` is used
                      within another computation. If `recompute_safely=false`,
                      `AveragedField` will *not* be recomputed before computing any dependent
                      computations if `AveragedField.status` is consistent with the current state of the simulation.
                      If `recompute_safely=true`, `AveragedField` is always recomputed
                      before performing a dependent computation.

Examples
=======

```julia
julia> using Oceananigans

julia> grid = RectilinearGrid(size=(2, 2, 2), x=(0, 1), y=(0, 1), z=(0, 1));

julia> c = CenterField(CPU(), grid);

julia> C_xy = AveragedField(c, dims=(1, 2)) # average over x, y
AveragedField over dims=(1, 2) located at (⋅, ⋅, Center) of Field located at (Center, Center, Center)
├── data: OffsetArrays.OffsetArray{Float64, 3, Array{Float64, 3}}, size: (1, 1, 2)
├── grid: RectilinearGrid{Float64, Periodic, Periodic, Bounded}(Nx=2, Ny=2, Nz=2)
├── dims: (1, 2)
├── operand: Field located at (Center, Center, Center)
└── status: time=0.0

julia> C_z = AveragedField(c, dims=3) # averaged over z
AveragedField over dims=(3,) located at (Center, Center, ⋅) of Field located at (Center, Center, Center)
├── data: OffsetArrays.OffsetArray{Float64, 3, Array{Float64, 3}}, size: (2, 2, 1)
├── grid: RectilinearGrid{Float64, Periodic, Periodic, Bounded}(Nx=2, Ny=2, Nz=2)
├── dims: (3,)
├── operand: Field located at (Center, Center, Center)
└── status: time=0.0
```
"""
function AveragedField(operand::AbstractField; dims, data=nothing, recompute_safely=true)

    arch = architecture(operand)
    loc = reduced_location(location(operand), dims=dims)
    grid = operand.grid

    if isnothing(data)
        data = new_data(arch, grid, loc)
        recompute_safely = false
    end

    return AveragedField{loc[1], loc[2], loc[3]}(data, arch, grid, dims, operand,
                                                 recompute_safely=recompute_safely)
end

"""
    compute!(avg::AveragedField, time=nothing)

Compute the average of `avg.operand` and store the result in `avg.data`.
"""
function compute!(avg::AveragedField, time=nothing)
    compute_at!(avg.operand, time)
    mean!(avg, avg.operand)
    return nothing
end

compute_at!(avg::AveragedField{X, Y, Z, <:FieldStatus}, time) where {X, Y, Z} =
    conditional_compute!(avg, time)

#####
##### Adapt
#####

Adapt.adapt_structure(to, averaged_field::AveragedField{X, Y, Z}) where {X, Y, Z} =
    AveragedField{X, Y, Z}(Adapt.adapt(to, averaged_field.data), nothing,
                           nothing, averaged_field.dims, nothing, nothing)


text:
###############################################################################
#
# CanopyLayer parameters container
#
###############################################################################
"""
    struct CanopyLayer{FT}

Struct to store leaf information (multi-dimensional).

# Fields
$(TYPEDFIELDS)
"""
Base.@kwdef mutable struct CanopyLayer{FT<:AbstractFloat}
    # CanopyLayer photosynthesis system
    "leaf photosynthesis system"
    ps  ::Leaf{FT} = Leaf{FT}()
    "Memory leaf photosynthesis system"
    ps_m::Leaf{FT} = Leaf{FT}()
    "Total leaf area `[m²]`"
    LA    ::FT = 150
    "Leaf area index in the layer"
    LAI   ::FT = 3
    "Total leaf area index in the layer"
    tLAI  ::FT = 3
    "Memory APAR `[μmol m⁻² s⁻¹]`"
    APAR_m::FT = 500
    "Memory environment"
    envir_m::AirLayer{FT} = AirLayer{FT}()

    # Number of leaves per canopy layer
    n_leaf::Int = 325

    # Temperature related, different for each leaf
    "Sensible Heat Flux `[W m⁻²]`"
    H ::Array{FT,1} = zeros(FT, n_leaf)
    "Latent Heat Flux `[W m⁻²]`"
    LE::Array{FT,1} = zeros(FT, n_leaf)
    "Net Radiation Balance `[W m⁻²]`"
    Rn::Array{FT,1} = zeros(FT, n_leaf)

    # Tempearture related, same for all leaves
    "Latent Heat of evaporation `[J mol⁻¹]`"
    LV   ::FT = latent_heat_vapor(T_25(FT)) * M_H₂O(FT)
    "Temperature `[K]`"
    T    ::FT = T_25(FT)
    "Old temperature `[K]`"
    T_old::FT = FT(0)
    "Leaf width `[m]`"
    width::FT = FT(0.05)

    # Diffusive conductances, same for all leaves
    "Boundary layer conductance to CO₂ `[mol m⁻² s⁻¹]`"
    g_bc::Array{FT,1} = zeros(FT, n_leaf) .+ FT(3/1.35)
    "Boundary layer conductance to heat `[mol m⁻² s⁻¹]`"
    g_bh::Array{FT,1} = zeros(FT, n_leaf) .+ FT(3)
    "Boundary layer conductance to H₂O `[mol m⁻² s⁻¹]`"
    g_bw::Array{FT,1} = zeros(FT, n_leaf) .+ FT(3)
    "Leaf diffusive conductance to water CO₂ `[mol m⁻² s⁻¹]`"
    g_lc::Array{FT,1} = zeros(FT, n_leaf) .+ FT(0.08032)
    "Leaf diffusive conductance to water H₂O `[mol m⁻² s⁻¹]`"
    g_lw::Array{FT,1} = zeros(FT, n_leaf) .+ FT(0.1519)
    "Mesophyll conductance for CO₂ `[mol m⁻² s⁻¹]`"
    g_m ::Array{FT,1} = zeros(FT, n_leaf) .+ FT(0.5)
    "Stomatal conductance to water CO₂ `[mol m⁻² s⁻¹]`"
    g_sc::Array{FT,1} = zeros(FT, n_leaf) .+ FT(0.1)
    "Stomatal conductance to water H₂O `[mol m⁻² s⁻¹]`"
    g_sw::Array{FT,1} = zeros(FT, n_leaf) .+ FT(0.16)

    # Diffusive conductances, same for all leaves
    "Gias correction constant"
    g_ias_c::FT = FT(0)
    "Gias correction exponent"
    g_ias_e::FT = FT(0.3)
    "Maximal leaf diffusive conductance `[mol m⁻² s⁻¹]`"
    g_max  ::FT = FT(0.8)
    "Maximal leaf diffusive conductance at 298.15 K `[mol m⁻² s⁻¹]`"
    g_max25::FT = FT(0.8)
    "Minimal leaf diffusive conductance `[mol m⁻² s⁻¹]`"
    g_min  ::FT = FT(0.025)
    "Minimal leaf diffusive conductance at 298.15 K `[mol m⁻² s⁻¹]`"
    g_min25::FT = FT(0.025)

    # CO₂ and H₂O pressures, different for each leaf
    "Leaf internal CO₂ partial pressure `[Pa]`"
    p_i::Array{FT,1} = zeros(FT, n_leaf) .+ FT(10)
    "Leaf surface CO₂ partial pressure `[Pa]`"
    p_s::Array{FT,1} = zeros(FT, n_leaf) .+ FT(40)

    # CO₂ and H₂O pressures, same for all leaves
    "Leaf saturation vapor pressure `[Pa]`"
    p_sat::FT = saturation_vapor_pressure(T)

    # Photosynthesis related, different for each leaf
    "RubisCO limited photosynthetic rate `[μmol m⁻² s⁻¹]`"
    Ac   ::Array{FT,1} = zeros(FT, n_leaf)
    "Light limited photosynthetic rate `[μmol m⁻² s⁻¹]`"
    Aj   ::Array{FT,1} = zeros(FT, n_leaf)
    "Gross photosynthetic rate `[μmol m⁻² s⁻¹]`"
    Ag   ::Array{FT,1} = zeros(FT, n_leaf)
    "Net photosynthetic rate `[μmol m⁻² s⁻¹]`"
    An   ::Array{FT,1} = zeros(FT, n_leaf)
    "Product limited photosynthetic rate `[μmol m⁻² s⁻¹]`"
    Ap   ::Array{FT,1} = zeros(FT, n_leaf)
    "Electron transport `[μmol m⁻² s⁻¹]`"
    J    ::Array{FT,1} = zeros(FT, n_leaf)
    "Potential Electron Transport Rate `[μmol m⁻² s⁻¹]`"
    J_pot::Array{FT,1} = zeros(FT, n_leaf)

    # Fluorescence related, different for each leaf
    "Total efficiency, incl. photorespiration `[mol CO₂ mol⁻¹ e-]`"
    e2c::Array{FT,1} = zeros(FT, n_leaf) .+ FT(1/6)
    "light adapted yield (`Kp=0`)"
    Fm′::Array{FT,1} = zeros(FT, n_leaf)
    "light-adapted fluorescence yield in the dark (`Kp=max`)"
    Fo′::Array{FT,1} = zeros(FT, n_leaf)
    "Actual electron transport rate `[μmol m⁻² s⁻¹]`"
    Ja ::Array{FT,1} = zeros(FT, n_leaf)
    "Non-Photochemical quenching "
    NPQ::Array{FT,1} = zeros(FT, n_leaf)
    "Photochemical quenching"
    qQ ::Array{FT,1} = zeros(FT, n_leaf)
    "energy quenching"
    qE ::Array{FT,1} = zeros(FT, n_leaf)
    "PSII yield"
    φ  ::Array{FT,1} = zeros(FT, n_leaf)
    "Steady-state (light-adapted) yield (aka Fs)"
    φs ::Array{FT,1} = zeros(FT, n_leaf)

    # Fluorescence related, same for all leaves
    "dark adapted yield (`Kp=0`)"
    Fm::FT = FT(0)
    "dark-adapted fluorescence yield (`Kp=max`)"
    Fo::FT = FT(0)

    # Environment related, different for each leaf
    "Absorbed photosynthetic active radiation `[μmol m⁻² s⁻¹]`"
    APAR::Array{FT,1} = zeros(FT, n_leaf) .+ 100
    "Leaf area fractions"
    LAIx::Array{FT,1} = ones(FT, n_leaf) ./ n_leaf;

    # Stomtal optimization related, different for each leaf
    "Maximal photosynthetic rate `[μmol m⁻² s⁻¹]`"
    a_max::Array{FT,1} = zeros(FT, n_leaf)
    "Flow rate `[mol m⁻² s⁻¹]`"
    e    ::Array{FT,1} = zeros(FT, n_leaf)

    # Stomtal optimization related, same for all leaves
    "Critical flow rate `[mol m⁻² s⁻¹]`"
    ec    ::FT = FT(2e-9)
    "Maximal hydraulic conductance ratio"
    kr_max::FT = FT(1)
    "Base xylem pressre `[MPa]`"
    p_ups ::FT = FT(0)
    "Base xylem pressre memory `[MPa]`"
    p_old ::FT = FT(1)
    "Fitness factor for nighttime stomtal conductance"
    ff    ::FT = FT(0.15)

    # time constant related to prognostic stomatal conductance
    "τ for empirical stomatal models `[-]`, Δg/Δt = (g_ss - gsw) / τ"
    τ_esm::FT = 600
    "τ for optimal stomatal models `[μmol⁻¹]`, Δg/Δt = (∂A/∂E - ∂Θ/∂E) * τ"
    τ_osm::FT = FT(1e-6)
    "τ for nighttime optimal stomatal models `[μmol⁻¹]`"
    τ_noc::FT = FT(2e-6)
end

max_stars_repo_name: climate-machine/Land

max_forks_repo_name: climate-machine/Land


text:
using DFControl

#This example goes through how one would create a job from scratch, using a .cif file for the Structure.

#First go to your favourite Crystal structure database and download the .cif you want to use.
#e.g. Si (F d -3 m :1) : http://www.crystallography.net/cod/9011998.cif

#We want to run an 'scf' and 'bands' calculation using QuantumEspresso.

#Variables that will be passed to the `DFJob` constructor.

name = "Si" #this name will also be given to the Structure inside the DFJob
local_dir = "/home/ponet/Documents/Si"
server_dir = "/home/ponet/Si"
bin_dir = "/usr/local/bin" #this is defaulted to the users bin dir = "~/bin/", it is the directory where pw.x etc will be called from

execs = [Exec("mpirun", bin_dir, Dict{Symbol, Any}(:np => 24)), Exec("pw.x", bin_dir, Dict{Symbol, Any}(:nk => 2))]
 #These execs are what will ultimately run the input, namely they will get pasted one after the other in the line of the job file.
 #If you don't want to use mpirun, just insert an Exec().

pseudoset = :pbesol #nonrelativistic calculation ( assumes you set up the pseudos, as demonstrated in the README)
pseudospecifier = "paw" #this selects the correct pseudo if multiple belong to the pseudoset. If you don't specify this, the first one in the set will be used.

#The header holds all the other information inside a job scriptfile that is not recognized as input and output.
header = ["#SBATCH -N 1", "#SBATCH --ntasks-per-node=24",
          "#SBATCH --time=24:00:00", "#SBATCH -p defpart",
          "module load open-mpi/gcc/1.10.4-hfi", "module load mkl/2016.1.056"
         ]

#The various calculations we want to run and the flags and data to pass to them are defined in two ways:
#   - calculation specific flags and data are associated with the calculation they belong to
#   - common flags can be defined as Pair{Symbol, Any} varargs at the end of the constructor call.

scf_data = Dict(:k_points => [6, 6, 6, 1, 1, 1], :flags => [:verbosity => "low"])
bands_data = Dict(:k_points => [[0.5, 0.5, 0.5, 100.],
                                [0.0, 0.0, 0.0, 100.],
                                [0.0, 0.5, 0.0, 1.]],
                  :flags => [:verbosity => "high", :nbnd => 8])

nscf_data = merge(bands_data, Dict(:k_points => (10, 10, 10)))
 #the order here is the order in which the calculations will run! The first string in the tuple is the executable name that will be ran, which should be in the bin dir.

#Now we load the cif file and create a `DFJob` from it.
calculations= [:scf => (execs, scf_data), :bands => (execs, bands_data), :nscf => (execs, nscf_data)]

job = DFJob(name, local_dir, "/home/ponet/Downloads/9011998.cif", calculations,
      :prefix       => "$name",
      :restart_mode => "from_scratch",
      :ecutwfc      => 18.0,
      :mixing_mode  => "plain",
      :mixing_beta  => 0.7,
      :conv_thr     => 1.0e-8,
      #kwargs
      server_dir  = server_dir,
      bin_dir     = bin_dir,
      header      = header,
      pseudoset  = :pbesol,
      pseudospecifier = pseudospecifier
     )
# An additional kwarg is `server=getdefault_server()`, which is set to the server you have defined while following the setup in README.
# This can ofcourse be setd to a different server.

#Now the job can be submitted to the server to run.
submit(job)
#this first saves the job and it's input files to the `job.local_dir` then pushes the `job.tt` file and the inputs to the `job.server_dir` on `job.server`, and runs the `qsub job.tt` command.
#You can check the job.local_dir to see the input files and `job.tt` script.

#you can observe the slurm qstat by doing
qstat()
#or watch it by
#these default to run the commands on the default server

#hopefully everything went according to plan and we can watch our pulloutputs
out = outputdata(job)

#now the bandstructure can be plotted
bands = out["bands"][:bands]
#or
bands = readbands(job["bands"])

fermi = readfermi(job["scf"])[:fermi]
using Plots

plot(bands, fermi=fermi)


text:
module EVOCLUS

  using StatsBase, Clustering, LightGraphs

  export # Mutations
         inversion!, insertion!, swap2!, scramble!, shifting!,
         # Recombinations
         pmx, cx, ox1, ox2, pos,
         # Selections
         ranklinear, tournament, roulette, sus,
         # Algorithms
         sGA, pcGA,
         # Population Generators
         Gen_perm, clustGen,
         ## Auto Population Generators
         Gen_Kmedian, Gen_Kmean, Gen_Kgrid, Gen_Km85,Gen_NN,
         ## Partial Solve Pop Generators
         PGen_Kmedian, PGen_Kmean, PGen_Kgrid, PGen_Km85,
         # DBSCAN epsilon derivation methods
         eps_Kmedian, eps_Kmean, eps_grid, eps_randm85,eps_Q,
         # Nearest Neighbor
         nearest_neighbor,
         # Clustered Nearest Neighbor
         clearest_neighbor, Kclearest_neighbor, APclearest_neighbor,
         # Greedy
         greedy,
         # Clustered Greedy
         creedy, Kcreedy, APcreedy,
         # 2-opt
         two_opt, two_opt!

  ## Recombinations
  include("recombinations.jl")
  ## Mutations
  include("mutations.jl")
  ## Selections
  include("selections.jl")
  ## Utilities
  include("utils.jl")
  ## simple GA
  include("sGA.jl")
  ## partial GA
  include("pcGA.jl")
  ## Generators
  include("generators.jl")
  ## Partial Solve Generators
  include("Pgenerators.jl")
  ## DBSCAN Utilities
  include("dbscan_utils.jl")
  ## Nearest neighbor
  include("nearest_neighbor.jl")
  ## Clustered nearest_neighbor
  include("clearest_neighbor.jl")
  include("Kclearest_neighbor.jl")
  include("APclearest_neighbor.jl")
  ## Greedy
  include("greedy.jl")
  ## Clustered Greedy
  include("creedy.jl")
  include("Kcreedy.jl")
  include("APcreedy.jl")
  ## Two_opt
  include("2-opt.jl")

end # module


text:
type INIDRandomSequence{S<:ValueSupport,T<:UnivariateDistribution} <: AbstractIDSequence{S}
    distributions::Vector{T}
end
function INIDRandomSequence{T<:UnivariateDistribution}(distributions::Vector{T})
    S = supertype(T).parameters[2]
    return INIDRandomSequence{S,T}(distributions)
end

distributions(X::INIDRandomSequence) = X.distributions


text:
"""
    LogUniform(a,b)

A positive random variable `X` is log-uniformly with parameters `a` and `b` if the logarithm of `X` is `Uniform(log(a), log(b))`.
The *log uniform* distribution is also known as *reciprocal distribution*.
```julia
LogUniform(1,10)
```
External links

* [Log uniform distribution on Wikipedia](https://en.wikipedia.org/wiki/Reciprocal_distribution)
"""
struct LogUniform{T<:Real} <: ContinuousUnivariateDistribution
    a::T
    b::T
    LogUniform{T}(a::T, b::T) where {T <: Real} = new{T}(a, b)
end

function LogUniform(a::T, b::T; check_args::Bool=true) where {T <: Real}
    check_args && @check_args(LogUniform, 0 < a < b)
    LogUniform{T}(a, b)
end

LogUniform(a::Real, b::Real; check_args::Bool=true) = LogUniform(promote(a, b)...; check_args=check_args)

convert(::Type{LogUniform{T}}, d::LogUniform) where {T<:Real} = LogUniform(T(d.a), T(d.b); check_args=false)
Base.minimum(d::LogUniform) = d.a
Base.maximum(d::LogUniform) = d.b

#### Parameters
params(d::LogUniform) = (d.a, d.b)
partype(::LogUniform{T}) where {T<:Real} = T

#### Statistics

function mean(d::LogUniform)
    a, b = params(d)
    (b - a) / log(b/a)
end
function var(d::LogUniform)
    a, b = params(d)
    log_ba = log(b/a)
    (b^2 - a^2) / (2*log_ba) - ((b-a)/ log_ba)^2
end
mode(d::LogUniform)   = d.a
modes(d::LogUniform)  = partype(d)[]

function entropy(d::LogUniform)
    a,b = params(d)
    log(a * b) / 2 + log(log(b / a))
end
#### Evaluation
function pdf(d::LogUniform, x::Real)
    x1, a, b = promote(x, params(d)...) # ensure e.g. pdf(LogUniform(1,2), 1f0)::Float32
    res = inv(x1 * log(b / a))
    return insupport(d, x1) ? res : zero(res)
end
function cdf(d::LogUniform, x::Real)
    x1, a, b = promote(x, params(d)...) # ensure e.g. cdf(LogUniform(1,2), 1f0)::Float32
    x1 = clamp(x1, a, b)
    return log(x1 / a) / log(b / a)
end
logpdf(d::LogUniform, x::Real) = log(pdf(d,x))

function quantile(d::LogUniform, p::Real)
    p1,a,b = promote(p, params(d)...) # ensure e.g. quantile(LogUniform(1,2), 1f0)::Float32
    exp(p1 * log(b/a)) * a
end

function kldivergence(p::LogUniform, q::LogUniform)
    ap, bp, aq, bq = promote(params(p)..., params(q)...)
    finite = aq <= ap < bp <= bq
    res = log(log(bq / aq) / log(bp / ap))
    return finite ? res : oftype(res, Inf)
end


text:
#///////////////////////////////////////
#// File Name: cross_entropy_bilevel_optimization_test.jl
#// Author: Haruki Nishimura (hnishimura@stanford.edu)
#// Date Created: 2020/11/03
#// Description: Test code for src/cross_entropy_bilevel_optimization.jl
#///////////////////////////////////////

using Test
using Random
@everywhere using LinearAlgebra

@testset "Cross Entropy Bilevel Optimization Test" begin
    @everywhere f(x, u) = x.^1.3 + u.^1.5;
    @everywhere c(k, x, u) = sum(x.^2.5 + u.^2.5);
    @everywhere h(x) = 1.0;
    @everywhere W(k) = Matrix(0.01I, 2, 2);
    N = 10;

    x_0 = zeros(2)
    u_array = [0.1*ones(2) for ii = 1 : N];

    problem = FiniteHorizonRiskSensitiveOptimalControlProblem(f, c, h, W, N)

    solver = CrossEntropyBilevelOptimizationSolver(num_samples=3);
    initialize!(solver)

    θ_array = [0.1, 0.3, 0.43];
    kl_bound = 1.0
    costs = compute_cost(solver, problem, x_0, u_array, θ_array, kl_bound)

    costs_test = compute_cost_serial(solver, problem, x_0, u_array, θ_array, kl_bound)
    @test all(isapprox(costs, costs_test))

    θ_array = get_positive_samples(0.0, 1.0, 10, MersenneTwister(123));
    @test all(θ_array .> 0.0) && length(θ_array) == 10

    rng = MersenneTwister(12344)
    θ_opt, x_array, l_array, L_array, c_opt =
    solve!(solver, problem, x_0, u_array, rng, kl_bound=kl_bound, verbose=false)
    @test !isinf(c_opt)
    @test !isnan(θ_opt)
end


text:
using Pkg
using JuMP;
using Plots;
using Distributions
using Random

#l
function simul_3()
    sigma2epsilon = 0.1
    sigma2eta = 0.2
    sigma2zeta = 0.3
    sigma2omegas = 0.1
    sigma2omegaa = 0.25

    L = 1000

    d = Normal(0, sigma2epsilon)
    epsilon = rand(d, L)
    d = Normal(0, sigma2eta)
    eta = rand(d, L)
    d = Normal(0, sigma2zeta)
    zeta = rand(d, L)
    d = Normal(0, sigma2omegas)
    omegaS1 = rand(d, L)
    d = Normal(0, sigma2omegas)
    omegaS2 = rand(d, L)
    d = Normal(0, sigma2omegaa)
    omegaA1 = rand(d, L)
    d = Normal(0, sigma2omegaa)
    omegaA2 = rand(d, L)

    mu = zeros(L)
    beta = zeros(L)
    y = zeros(L)
    mu[1] = 1
    beta[1] = 0.5

    gammaS1 = zeros(L, 3)
    gammaS2 = zeros(L, 3)
    gammaA1 = zeros(L, 182)
    gammaA2 = zeros(L, 182)

    for i in 1:L-1
        beta[i+1] = beta[i] + zeta[i]
        mu[i+1] = mu[i] + beta[i] + eta[i]
        for j = 1:3
            gammaS1[i+1,j] = cos(2*pi/3)*gammaS1[i,j] + sin(2*pi/3)*gammaS2[i,j] + omegaS1[i]
            gammaS2[i+1,j] = -sin(2*pi/3)*gammaS1[i,j] + cos(2*pi/3)*gammaS2[i,j] + omegaS2[i]
        end
        for j = 1:182
            gammaA1[i+1,j] = cos(2*pi/182)*gammaA1[i,j] + sin(2*pi/182)*gammaA2[i,j] + omegaA1[i]
            gammaA2[i+1,j] = -sin(2*pi/182)*gammaA1[i,j] + cos(2*pi/182)*gammaA2[i,j] + omegaA2[i]
        end
        y[i] = mu[i] + sum(gammaS1[i,:]) + sum(gammaA1[i,:]) + epsilon[i]
    end

    return y
end
function plot_3()
    p = plot(simul_3())
    plot!(simul_3())
    plot!(simul_3())
    plot!(simul_3())
    plot!(simul_3())
    savefig(p,"Modelos Estruturais\\Lista 1\\imagens\\3.png")
end

plot_3()