import%20marimo%0A%0A__generated_with%20%3D%20%220.12.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20A%20*geometric%20program%20(GP)*%20is%20a%20type%20of%20mathematical%20optimization%20problem%20characterized%20by%20objective%20and%20constraint%20functions%20that%20have%20a%20special%20form.%20To%20describe%20the%20said%20special%20form%2C%20one%20will%20require%20the%20following%20definitions%3A%0A%0A%20%20%20%20%20%20%20%20The%20smallest%20terms%20creating%20the%20GPs%20are%20called%20*monomials*.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Monomial%20functions%0A%0A%20%20%20%20%20%20%20%20Let%20%5C(%20x_1%2C%20%5Cdots%2C%20x_n%20%5C)%20denote%20%5C(%20n%20%5C)%20real%20positive%20variables%2C%20and%20%5C(%20x%20%3D%20(x_1%2C%20%5Cdots%2C%20x_n)%20%5C)%20a%20vector%20with%20components%20%5C(%20x_i%20%5C).%20A%20real-valued%20function%20%5C(%20f%20%5C)%20of%20%5C(%20x%20%5C)%2C%20with%20the%20form%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20f(x)%20%3D%20c%20x_1%5E%7Ba_1%7D%20x_2%5E%7Ba_2%7D%20%5Ccdots%20x_n%5E%7Ba_n%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20where%20%5C(%20c%20%3E%200%20%5C)%20and%20%5C(%20a_i%20%5Cin%20%5Cmathbb%7BR%7D%20%5C)%2C%20is%20called%20a%20**monomial%20function**%2C%20or%20more%20informally%2C%20a%20**monomial**%20(of%20the%20variables%20%5C(%20x_1%2C%20%5Cdots%2C%20x_n%20%5C)).%20We%20refer%20to%20the%20constant%20%5C(%20c%20%5C)%20as%20the%20**coefficient**%20of%20the%20monomial%2C%20and%20we%20refer%20to%20the%20constants%20%5C(%20a_1%2C%20%5Cdots%2C%20a_n%20%5C)%20as%20the%20**exponents**%20of%20the%20monomial.%0A%0A%20%20%20%20%20%20%20%20As%20an%20example%2C%20%5C(%202.3%20x_1%5E2%20x_2%5E%7B-0.15%7D%20%5C)%20is%20a%20monomial%20of%20the%20variables%20%5C(%20x_1%20%5C)%20and%20%5C(%20x_2%20%5C)%2C%20with%20coefficient%202.3%20and%20%5C(%20x_2%20%5C)-exponent%20%5C(%20-0.15%20%5C).%0A%0A%20%20%20%20%20%20%20%20Any%20positive%20constant%20is%20a%20monomial%2C%20as%20is%20any%20variable.%20Monomials%20are%20closed%20under%20multiplication%20and%20division%3A%20if%20%5C(%20f%20%5C)%20and%20%5C(%20g%20%5C)%20are%20both%20monomials%2C%20then%20so%20are%20%5C(%20f%20*%20g%20%5C)%20and%20%5C(%20f%20%2F%20g%20%5C)%20(this%20includes%20scaling%20by%20any%20positive%20constant).%20A%20monomial%20raised%20to%20any%20power%20is%20also%20a%20monomial%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20f(x)%5Ey%20%3D%20(c%20x_1%5E%7Ba_1%7D%20x_2%5E%7Ba_2%7D%20%5Ccdots%20x_n%5E%7Ba_n%7D)%5Ey%20%3D%20c%5Ey%20x_1%5E%7Ba_1%20y%7D%20x_2%5E%7Ba_2%20y%7D%20%5Ccdots%20x_n%5E%7Ba_n%20y%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Posynomial%20functions%0A%0A%20%20%20%20%20%20%20%20A%20sum%20of%20one%20or%20more%20monomials%2C%20i.e.%2C%20a%20function%20of%20the%20form%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20f(x)%20%3D%20%5Csum_%7Bk%3D1%7D%5E%7BK%7D%20c_k%20x_1%5E%7Ba_%7B1k%7D%7D%20x_2%5E%7Ba_%7B2k%7D%7D%20%5Ccdots%20x_n%5E%7Ba_%7Bnk%7D%7D%2C%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%20%20%20%20%20%20%20%20where%20%24c_k%20%3E%200%24%2C%20is%20called%20a%20*posynomial%20function*%20or%2C%20more%20simply%2C%20a%20*posynomial*%20(with%20%24K%24%20terms%2C%20in%20the%20variables%20%24x_1%2C%20%5Cldots%2C%20x_n%24).%20Any%20monomial%20is%20also%20a%20posynomial.%20%0A%0A%20%20%20%20%20%20%20%20For%20example%20each%20of%20the%20following%20terms%20are%20monomials%20(thus%20also%20posynomials)%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%200.5%7Bx%7D%7By%7D%2C%20%5Cquad%202x%5E2%5Csqrt%7Bz%7D%2C%20%5Cquad%20xyz%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%20%20%20%20%20%20%20%20And%20the%20sumation%20of%20these%20monomials%20is%20a%20polynomial.%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%200.5%7Bx%7D%7By%7D%20%2B%202x%5E2%5Csqrt%7Bz%7D%20%2B%20xyz%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Standard%20Form%20of%20a%20Geometric%20Program%0A%0A%20%20%20%20%20%20%20%20A%20**Geometric%20Program%20(GP)**%20is%20an%20optimization%20problem%20of%20the%20following%20form%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Cbegin%7Baligned%7D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bminimize%7D%20%5Cquad%20%26%20f_0(x)%20%5C%5C%0A%20%20%20%20%20%20%20%20%5Ctext%7Bsubject%20to%7D%20%5Cquad%20%26%20f_i(x)%20%5Cleq%201%2C%20%5Cquad%20i%20%3D%201%2C%20%5Cdots%2C%20m%20%5C%5C%0A%20%20%20%20%20%20%20%20%26%20x_j%20%3E%200%2C%20%5Cquad%20j%20%3D%201%2C%20%5Cdots%2C%20n%0A%20%20%20%20%20%20%20%20%5Cend%7Baligned%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20Where%3A%0A%0A%20%20%20%20%20%20%20%20-%20%5C(%20f_0%20%3A%20%5Cmathbb%7BR%7D_%7B%2B%7D%5En%20%5Cto%20%5Cmathbb%7BR%7D_%7B%2B%7D%20%5C)%20is%20a%20**posynomial%20objective%20function**%2C%0A%20%20%20%20%20%20%20%20-%20Each%20%5C(%20f_i%20%3A%20%5Cmathbb%7BR%7D_%7B%2B%7D%5En%20%5Cto%20%5Cmathbb%7BR%7D_%2B%20%5C)%20is%20a%20**posynomial%20inequality%20constraint**.%0A%0A%20%20%20%20%20%20%20%20The%20problem%20is%20**not%20convex**%20in%20this%20form%20due%20to%20the%20nonlinear%20structure%20of%20monomials%20and%20posynomials.%20However%2C%20it%20can%20be%20convexified%20using%20a%20logarithmic%20transformation%20and%20can%20also%20be%20represented%20in%20an%20exponential%20cone.%20The%20next%20section%20provides%20a%20tool%20that%20solves%20the%20geometric%20programs%2C%20handling%20the%20transformations%20automatically.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Geometric%20Programming%20Tool%0A%0A%20%20%20%20%20%20%20%20The%20tool%20initializes%20an%20optimization%20model%20and%20provides%20the%20following%20core%20functions%20for%20model%20construction%20and%20analysis%3A%0A%0A%20%20%20%20%20%20%20%20-%20**%60printModel()%60**%20%E2%80%94%20Outputs%20the%20current%20model%20structure%20in%20a%20readable%20format.%0A%20%20%20%20%20%20%20%20-%20**%60addObjective(Monomial)%60**%20%E2%80%94%20Defines%20and%20adds%20the%20objective%20function%20to%20the%20model.%0A%20%20%20%20%20%20%20%20-%20**%60addConstraint(List%20of%20Monomials)%60**%20%E2%80%94%20Adds%20one%20or%20more%20constraints%20to%20the%20model%20formulation.%0A%20%20%20%20%20%20%20%20-%20**%60Solve()%60**%20%E2%80%94%20Solves%20the%20model%20once%20all%20components%20(objective%20and%20constraints)%20are%20defined.%0A%20%20%20%20%20%20%20%20-%20**%60analyse()%60**%20%E2%80%94%20Prints%20key%20specifications%20and%20diagnostics%20of%20the%20model.%0A%20%20%20%20%20%20%20%20-%20**%60evaluateObjective()%60**%20%E2%80%94%20Computes%20the%20value%20of%20the%20objective%20function%20for%20the%20obtained%20solution.%0A%0A%20%20%20%20%20%20%20%20The%20class%20and%20function%20definitions%2C%20as%20well%20as%20the%20model%20implementation%2C%20can%20be%20found%20in%20the%20Appendix.%0A%0A%20%20%20%20%20%20%20%20With%20only%20using%20these%20functionalities%2C%20one%20can%20solve%20a%20geometric%20program%20without%20further%20implementation.%20Let's%20go%20over%20an%20example.%20Say%20we%20model%20the%20following%20problem%3A%20%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Minimize%3A%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20x%20%2B%20y%5E2%20z%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Subject%20to%3A%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%200.1%5Csqrt%7Bx%7D%20%2B%202y%5E%7B-1%7D%20%5Cleq%201%2C%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20z%5E%7B-1%7D%20%2B%20yx%5E%7B-2%7D%20%5Cleq%201.%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%0A%20%20%20%20%20%20%20%20To%20initialize%20a%20geometric%20program%2C%20call%20the%20*GeometricProgramming(m%2Cn)*%20class%2C%20with%20inputs%20m%20%3D%20number%20of%20constraint%2C%20n%20%3D%20number%20of%20variables.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(GeometricProgramming)%3A%0A%20%20%20%20gp%20%3D%20GeometricProgramming(2%2C%203)%20%23%20m%2Cn%20%3D%20(%23)%20of%20constraints%2C%20(%23)%20of%20variables%0A%20%20%20%20return%20(gp%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20The%20objective%20function%20in%20a%20geometric%20program%20is%2C%20by%20definition%2C%20minimized.%20The%20%60addObjective(%5BMonomial%2C%20...%5D)%60%20function%20accepts%20either%20a%20single%20%60Monomial%60%20object%20or%20a%20list%20of%20%60Monomial%60%20objects%20as%20input.%0A%0A%20%20%20%20%20%20%20%20A%20%60Monomial%60%20object%20can%20be%20constructed%20using%20the%20following%20method%3A%0A%0A%20%20%20%20%20%20%20%20%60Monomial.add(coefficient%2C%20indices%2C%20alphas)%60%0A%0A%20%20%20%20%20%20%20%20-%20**%60coefficient%60**%3A%20%5C(%20c%20%5C)%2C%20a%20positive%20scalar%20%20%0A%20%20%20%20%20%20%20%20-%20**%60indices%60**%3A%20an%20array%20of%20selected%20variable%20indices%20%5C(%20i%20%5Cin%20%5C%7B1%2C%20%5Cdots%2C%20N%5C%7D%20%5C)%20%20%0A%20%20%20%20%20%20%20%20%20%20_Example_%3A%20To%20add%20a%20monomial%20involving%20%5C(%20y%20%5C)%20and%20%5C(%20z%20%5C)%20from%20the%20list%20%5C(%20x%2C%20y%2C%20z%2C%20w%20%5C)%2C%20input%20%60indices%20%3D%20%5B1%2C2%5D%60%20%20%0A%20%20%20%20%20%20%20%20-%20**%60alphas%60**%3A%20an%20array%20of%20exponents%20%5C(%20a_i%20%5C)%20corresponding%20to%20each%20selected%20variable%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Monomial%2C%20gp)%3A%0A%20%20%20%20gp.addObjective(%5B%0A%20%20%20%20%20%20%20%20Monomial.add(1%2C%20%5B0%5D%2C%20%5B1%5D)%2C%20%23%20x%0A%20%20%20%20%20%20%20%20Monomial.add(1%2C%20%5B1%2C2%5D%2C%20%5B2%2C1%5D)%20%23%20y%5E2%20*%20z%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20By%20definition%2C%20all%20constraint%20posynomials%20in%20a%20geometric%20program%20must%20be%20less%20than%20or%20equal%20to%201.%20Similar%20to%20the%20objective%20function%2C%20constraints%20can%20be%20added%20using%20the%20%60addConstraint(constraintIndex%2C%20%5BMonomial%2C%20...%5D)%60%20function.%20%0A%0A%20%20%20%20%20%20%20%20This%20function%20accepts%20a%20constraint%20index%20and%20either%20a%20single%20%60Monomial%60%20object%20or%20a%20list%20of%20%60Monomial%60%20objects%20as%20input.%20Monomials%20can%20be%20added%20individually%20or%20collectively%20in%20a%20single%20call.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Monomial%2C%20gp)%3A%0A%20%20%20%20%23First%20Constraint%2C%20%3C%3D%201%0A%20%20%20%20gp.addConstraint(0%2C%20%5B%0A%20%20%20%20%20%20%20%20Monomial.add(0.1%2C%20%5B0%5D%2C%20%5B0.5%5D)%2C%20%23%200.1%20*%20x%5E(0.5)%0A%20%20%20%20%20%20%20%20Monomial.add(2%2C%20%5B1%5D%2C%20%5B-1%5D)%20%23%202%20*%20y%5E-1%0A%20%20%20%20%5D)%0A%0A%20%20%20%20%23Second%20Constraint%20-%20First%20Monomial%20%0A%20%20%20%20gp.addConstraint(1%2C%20Monomial.add(1%2C%20%5B2%5D%2C%20%5B-1%5D))%20%23%20z%5E-1%0A%0A%20%20%20%20%23Second%20Constraint%20-%20Second%20Monomial%2C%20%3C%3D%201%0A%20%20%20%20gp.addConstraint(1%2C%20Monomial.add(1%2C%20%5B0%2C1%5D%2C%20%5B-2%2C1%5D))%20%23x%5E-2%20*%20y%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20%60printModel()%60%20function%20provides%20a%20convenient%20way%20to%20display%20the%20current%20model%2C%20including%20the%20objective%20function%20and%20all%20defined%20constraints%2C%20in%20a%20readable%20format.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(gp)%3A%0A%20%20%20%20gp.printModel()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Once%20the%20entire%20model%20has%20been%20defined%2C%20the%20problem%20can%20be%20solved%20using%20the%20%60Solve()%60%20function.%20This%20function%20returns%20both%20the%20solution%20object%20and%20the%20values%20of%20the%20decision%20variables.%20If%20needed%2C%20the%20user%20can%20further%20interact%20with%20the%20solution%20object%20for%20additional%20information.%0A%0A%20%20%20%20%20%20%20%20Using%20the%20retrieved%20decision%20variable%20values%2C%20the%20user%20can%20also%20compute%20the%20objective%20function%20value.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(gp)%3A%0A%20%20%20%20sol%2C%20variables%20%3D%20gp.Solve()%20%23solve%20the%20model%0A%20%20%20%20return%20sol%2C%20variables%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20objective%20function%20value%20can%20be%20calculated%20using%20the%20%60evaluateObjective(variables)%60%20function%2C%20based%20on%20the%20decision%20variable%20values%20obtained%20from%20the%20solution.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(gp%2C%20np%2C%20sol%2C%20variables)%3A%0A%20%20%20%20obj_val%20%3D%20gp.evaluateObjective(variables)%20%23Calculate%20the%20objective%20value%0A%20%20%20%20print(f%22Objective%20value%3A%20%7Bobj_val%3A.6f%7D%22)%0A%0A%20%20%20%20print(%22Optimal%20values%20of%20(x_i)%3A%22)%0A%20%20%20%20for%20i%2C%20val%20in%20enumerate(sol)%3A%0A%20%20%20%20%20%20%20%20print(f%22x_%7Bi%7D%20%3D%20%7Bnp.exp(val)%3A.6f%7D%22)%0A%20%20%20%20return%20i%2C%20obj_val%2C%20val%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Analyser%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20Writing%20well-structured%20geometric%20programs%20can%20sometimes%20be%20a%20non-trivial%20task.%20To%20assist%20with%20this%2C%20the%20analyse()%20function%20is%20included%20in%20the%20tool.%20This%20function%20provides%20a%20comprehensive%20summary%20and%20diagnostic%20of%20the%20model%2C%20helping%20users%20identify%20potential%20issues%20before%20solving.%0A%0A%20%20%20%20%20%20%20%20-%20**Constraints%20and%20Variables**%3A%20Prints%20the%20total%20number%20of%20constraints%20and%20decision%20variables.%0A%20%20%20%20%20%20%20%20-%20**Monomial%20Coefficients**%3A%20Shows%20the%20range%20of%20monomial%20coefficients%20(min%E2%80%93max)%2C%20if%20any%20are%20added.%0A%20%20%20%20%20%20%20%20-%20**Alpha%20Values**%3A%20Displays%20the%20range%20of%20non-zero%20absolute%20exponent%20values%20(alphas).%0A%20%20%20%20%20%20%20%20-%20**Degree%20of%20Difficulty**%3A%20%60totalMonomials%20-%20number%20of%20variables%20-%201%60%0A%20%20%20%20%20%20%20%20-%20**Variable%20Sign%20Check**%3A%20Issues%20warnings%20if%20a%20variable%20appears%20only%20with%20positive%20or%20only%20with%20negative%20exponents%20in%20all%20monomials%2C%20which%20helps%20identify%20potential%20modeling%20issues.%0A%0A%20%20%20%20%20%20%20%20%3Cins%3EVariable%20Sign%20Check%3C%2Fins%3E%20is%20a%20critical%20part%20of%20the%20model%20analysis%2C%20as%20it%20determines%20the%20potential%20solvability%20issues%20of%20the%20geometric%20program%20and%20can%20often%20be%20overlooked.%0A%0A%20%20%20%20%20%20%20%20If%2C%20for%20a%20decision%20variable%2C%20all%20the%20defined%20alpha%20values%20(exponents)%20have%20the%20same%20sign%E2%80%94either%20all%20positive%20or%20all%20negative%E2%80%94this%20may%20indicate%20a%20structural%20issue%20in%20the%20model%20that%20could%20hinder%20its%20solvability.%20When%20such%20a%20problem%20is%20encountered%2C%20the%20analyser%20function%20can%20help%20the%20user%20to%20identify%20the%20problem.%20%0A%0A%20%20%20%20%20%20%20%20Let's%20look%20at%20an%20example%20that%20illustrates%20this%20issue.%20Firstly%20the%20model%20below%20displays%20an%20example%20where%20the%20decision%20variable%20%24x%24%20combines%20both%20positive%20and%20negative%20alpha%20values.%20Therefore%2C%20MOSEK%20can%20retrieve%20the%20optimal%20solution%20easily.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(GeometricProgramming%2C%20Monomial)%3A%0A%20%20%20%20gp2%20%3D%20GeometricProgramming(0%2C%201)%20%23%20m%2Cn%20%3D%20(%23)%20of%20constraints%2C%20(%23)%20of%20variables%0A%20%20%20%20gp2.addObjective(%5B%0A%20%20%20%20%20%20%20%20Monomial.add(1%2C%20%5B0%5D%2C%20%5B2%5D)%2C%20%23%20x%5E2%0A%20%20%20%20%20%20%20%20Monomial.add(1%2C%20%5B0%5D%2C%20%5B-3%5D)%5D)%20%23%20y%5E%20(-3)%0A%0A%20%20%20%20gp2.printModel()%0A%20%20%20%20sol2%2Cvariables2%20%3D%20gp2.Solve()%20%23solve%20the%20model%0A%20%20%20%20return%20gp2%2C%20sol2%2C%20variables2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22As%20seen%20below%2C%20the%20analyse%20function%20does%20not%20warn%20the%20user%2C%20only%20presents%20the%20characteristics%20of%20the%20model.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(gp2)%3A%0A%20%20%20%20gp2.analyse()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22In%20the%20modified%20model%20below%2C%20the%20second%20monomial%20is%20discarded%20leaving%20the%20decision%20variable%20%24x%24%20only%20with%20a%20positive%20alpha%20value.%20Therefore%2C%20the%20%24x%24%20value%20will%20converge%20to%20_zero_%20while%20being%20strictly%20bigger%20then%20_zero_%2C%20resulting%20in%20the%20absence%20of%20an%20optimal%20solution.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(GeometricProgramming%2C%20Monomial)%3A%0A%20%20%20%20gp3%20%3D%20GeometricProgramming(0%2C%201)%20%23%20m%2Cn%20%3D%20(%23)%20of%20constraints%2C%20(%23)%20of%20variables%0A%20%20%20%20gp3.addObjective(Monomial.add(1%2C%20%5B0%5D%2C%20%5B2%5D))%20%23%20x%5E2%0A%0A%20%20%20%20gp3.printModel()%0A%20%20%20%20sol3%2Cvariables3%20%3D%20gp3.Solve()%20%23solve%20the%20model%0A%20%20%20%20return%20gp3%2C%20sol3%2C%20variables3%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Due%20to%20the%20described%20problem%2C%20the%20analyser%20warns%20the%20user%20about%20the%20weakness%20of%20the%20model.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(gp3)%3A%0A%20%20%20%20gp3.analyse()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Similarly%20to%20the%20example%20before%2C%20if%20the%20decision%20variable%20%24x%24%20is%20only%20left%20with%20a%20negative%20alpha%20value%20we%20will%20encounter%20infeasibility%20again.%20It%20can%20be%20easily%20seen%20that%20decision%20variable%20%24x%24%20will%20converge%20to%20infinity%2C%20making%20the%20problem%20unbounded.%20When%20called%2C%20the%20analyser%20again%20warns%20the%20user%20about%20the%20mentioned%20property.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(GeometricProgramming%2C%20Monomial)%3A%0A%20%20%20%20gp4%20%3D%20GeometricProgramming(0%2C%201)%20%23%20m%2Cn%20%3D%20(%23)%20of%20constraints%2C%20(%23)%20of%20variables%0A%20%20%20%20gp4.addObjective(Monomial.add(1%2C%20%5B0%5D%2C%20%5B-3%5D))%20%23%20x%5E(-3)%0A%0A%20%20%20%20gp4.printModel()%0A%20%20%20%20sol4%2Cvariables4%20%3D%20gp4.Solve()%20%23solve%20the%20model%0A%20%20%20%20gp4.analyse()%0A%20%20%20%20return%20gp4%2C%20sol4%2C%20variables4%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20Although%20this%20property%20can%20sometimes%20prevent%20a%20model%20from%20being%20solvable%2C%20there%20are%20cases%20where%20it%20can%20still%20be%20handled%20correctly.%20The%20following%20example%20presents%20a%20model%20with%20two%20decision%20variables%2C%20one%20of%20which%20appears%20only%20with%20positive%20exponents.%20In%20this%20case%2C%20due%20to%20the%20structure%20of%20the%20feasible%20region%2C%20an%20optimal%20solution%20exists.%20%0A%0A%20%20%20%20%20%20%20%20Nevertheless%2C%20this%20property%20should%20be%20treated%20as%20a%20potential%20risk%20and%20considered%20a%20diagnostic%20checkpoint%2C%20especially%20if%20the%20model%20fails.%20It%20can%20be%20flagged%20using%20the%20analyser%20function%20for%20early%20detection.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(GeometricProgramming%2C%20Monomial)%3A%0A%20%20%20%20gp5%20%3D%20GeometricProgramming(1%2C%202)%20%23%20m%2Cn%20%3D%20(%23)%20of%20constraints%2C%20(%23)%20of%20variables%0A%20%20%20%20gp5.addObjective(%5BMonomial.add(1%2C%20%5B0%5D%2C%20%5B2%5D)%2C%20%23x%5E2%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Monomial.add(1%2C%20%5B1%5D%2C%20%5B-1%5D)%5D)%20%23%20y%5E(-1)%0A%0A%20%20%20%20gp5.addConstraint(0%2C%5BMonomial.add(1%2C%5B0%5D%2C%5B1%5D)%2C%20Monomial.add(1%2C%5B1%5D%2C%5B1%5D)%5D)%0A%0A%20%20%20%20gp5.printModel()%0A%20%20%20%20sol5%2Cvariables5%20%3D%20gp5.Solve()%20%23solve%20the%20model%0A%20%20%20%20gp5.analyse()%0A%20%20%20%20return%20gp5%2C%20sol5%2C%20variables5%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Further%20Details%0A%0A%20%20%20%20%20%20%20%20As%20explained%20earlier%2C%20the%20problem%20is%20non-convex.%20To%20solve%20the%20problem%2C%20the%20following%20transformation%20from%20the%20non-convex%20form%20to%20an%20exponential%20cone%20representation%20can%20be%20applied%2C%20which%20is%20already%20handled%20by%20the%20geometric%20programming%20class.%0A%0A%20%20%20%20%20%20%20%20%23%23%23%20Logarithmic%20Transformation%20(Convexification)%0A%0A%20%20%20%20%20%20%20%20To%20reformulate%20a%20GP%20as%20a%20**convex%20problem**%2C%20we%20apply%20a%20change%20of%20variables%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20x_j%20%3D%20e%5E%7By_j%7D%20%5Cquad%20%5Ctext%7Bfor%20%7D%20j%20%3D%201%2C%20%5Cdots%2C%20n%0A%20%20%20%20%20%20%20%20%5Cquad%20%5CRightarrow%20%5Cquad%20x%20%3D%20e%5Ey%2C%20%5Cquad%20y%20%5Cin%20%5Cmathbb%7BR%7D%5En%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20A%20**monomial**%20becomes%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20f(x)%20%3D%20c%20%5Ccdot%20e%5E%7Ba%5ET%20y%7D%20%5Cquad%20%5CRightarrow%20%5Cquad%20%5Clog%20f(x)%20%3D%20%5Clog%20c%20%2B%20a%5ET%20y%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20A%20**posynomial**%20becomes%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20f(x)%20%3D%20%5Csum_%7Bk%3D1%7D%5EK%20c_k%20%5Ccdot%20e%5E%7Ba_k%5ET%20y%7D%20%5Cquad%20%5CRightarrow%20%5Cquad%20%5Clog%20f(x)%20%3D%20%5Clog%20%5Cleft(%20%5Csum_%7Bk%3D1%7D%5EK%20%5Cexp(a_k%5ET%20y%20%2B%20%5Clog%20c_k)%20%5Cright)%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20This%20is%20known%20as%20the%20**log-sum-exp%20function**%2C%20which%20is%20a%20**convex**%20function%20of%20%5C(%20y%20%5Cin%20%5Cmathbb%7BR%7D%5En%20%5C).%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%20Convex%20Reformulation%0A%0A%20%20%20%20%20%20%20%20The%20original%20GP%20is%20now%20transformed%20into%20the%20following%20**convex%20optimization%20problem**%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Cbegin%7Baligned%7D%0A%20%20%20%20%20%20%20%20%5Ctext%7Bminimize%7D%20%5Cquad%20%26%20t%20%5C%5C%0A%20%20%20%20%20%20%20%20%5Ctext%7Bsubject%20to%7D%20%5Cquad%20%26%20%5Clog%5Cleft(%20%5Csum_%7Bk%3D1%7D%5E%7BK_0%7D%20%5Cexp(a_k%5E%7B(0)%5Ctop%7D%20y%20%2B%20%5Clog%20c_k%5E%7B(0)%7D)%20%5Cright)%20%5Cleq%20t%20%5C%5C%0A%20%20%20%20%20%20%20%20%26%20%5Clog%5Cleft(%20%5Csum_%7Bk%3D1%7D%5E%7BK_i%7D%20%5Cexp(a_k%5E%7B(i)%5Ctop%7D%20y%20%2B%20%5Clog%20c_k%5E%7B(i)%7D)%20%5Cright)%20%5Cleq%200%2C%20%5Cquad%20i%20%3D%201%2C%20%5Cdots%2C%20m%0A%20%20%20%20%20%20%20%20%5Cend%7Baligned%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20Where%20%5C(%20t%20%5Cin%20%5Cmathbb%7BR%7D%20%5C)%20is%20a%20**scalar%20upper%20bound%20variable**.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%23%20Exponential%20Cone%20Representation%0A%0A%20%20%20%20%20%20%20%20The%20objective%20function%20constraint%20of%20the%20form%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Clog%5Cleft(%20%5Csum_%7Bk%3D1%7D%5E%7BK_0%7D%20%5Cexp(a_k%5E%7B(0)%5Ctop%7D%20y%20%2B%20%5Clog%20c_k%5E%7B(0)%7D)%20%5Cright)%20%5Cleq%20t%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20can%20be%20equivalently%20written%20as%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Csum_%7Bk%7D%20u_k%20%5Cleq%201%2C%20%5Cquad%20%5Ctext%7Bwith%7D%20%5Cquad%20(u_k%2C%201%2C%20(a_k%5E%7B(0)%5Ctop%7D%20y%20%2B%20%5Clog%20c_k%5E%7B(0)%7D%20-%20%5Ctau)%20%5Cin%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20Where%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%20%3A%3D%20%5Cleft%5C%7B%20(x%2C%20y%2C%20z)%20%5Cin%20%5Cmathbb%7BR%7D%5E3%20%5C%3B%5Cmiddle%7C%5C%3B%20y%20%3E%200%2C%5C%3B%20y%20%5Ccdot%20e%5E%7Bx%2Fy%7D%20%5Cleq%20z%20%5Cright%5C%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20And%20each%20constraint%20of%20the%20form%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Clog%5Cleft(%20%5Csum_%7Bk%3D1%7D%5E%7BK_i%7D%20%5Cexp%5Cleft(a_k%5E%7B(i)%5Ctop%7D%20y%20%2B%20%5Clog%20c_k%5E%7B(i)%7D%5Cright)%20%5Cright)%20%5Cleq%200%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20can%20be%20equivalently%20written%20as%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Csum_k%20u_k%20%5Cleq%201%2C%20%5Cquad%20%5Ctext%7Bwith%7D%20%5Cquad%20(u_k%2C%201%2C%20a_k%5E%7B(i)%5Ctop%7D%20y%20%2B%20%5Clog%20c_k%5E%7B(i)%7D)%20%5Cin%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20Where%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%20%3A%3D%20%5Cleft%5C%7B%20(x%2C%20y%2C%20z)%20%5Cin%20%5Cmathbb%7BR%7D%5E3%20%5C%3B%5Cmiddle%7C%5C%3B%20y%20%3E%200%2C%5C%3B%20y%20%5Ccdot%20e%5E%7Bx%2Fy%7D%20%5Cleq%20z%20%5Cright%5C%7D%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20This%20transforms%20the%20log-sum-exp%20constraint%20into%20a%20set%20of%20**conic%20constraints**%2C%20using%20**auxiliary%20variables**%20%5C(%20u_k%20%5C)%20and%20the%20**exponential%20cone**.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20---%0A%20%20%20%20%20%20%20%20Then%20we%20can%20apply%20this%20transformation%20to%20our%20original%20model%3A%20%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Minimize%3A%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20x%20%2B%20y%5E2%20z%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Subject%20to%3A%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%200.1%5Csqrt%7Bx%7D%20%2B%202y%5E%7B-1%7D%20%5Cleq%201%2C%0A%20%20%20%20%20%20%20%20%24%24%0A%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20z%5E%7B-1%7D%20%2B%20yx%5E%7B-2%7D%20%5Cleq%201.%0A%20%20%20%20%20%20%20%20%24%24%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20Let%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20x%20%3D%20e%5Eu%2C%20%5Cquad%20y%20%3D%20e%5Ev%2C%20%5Cquad%20z%20%3D%20e%5Ew%0A%20%20%20%20%20%20%20%20%5C%5D%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20Then%20we%20can%20apply%20the%20following%20transformation%3A%0A%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Minimize%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20t%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Subject%20to%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Clog%5Cleft(e%5Eu%20%2B%20e%5E%7B2v%20%2B%20w%7D%5Cright)%20%5Cleq%20t%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Clog%5Cleft(0.1e%5E%7Bu%2F2%7D%20%2B%202e%5E%7B-v%7D%5Cright)%20%5Cleq%200%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20%5Clog%5Cleft(e%5E%7B-w%7D%20%2B%20e%5E%7Bv%20-%202u%7D%5Cright)%20%5Cleq%200%0A%20%20%20%20%20%20%20%20%5C%5D%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Minimize%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20t%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20%24%5Cquad%5Cquad%5Cquad%24%20Subject%20to%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20(p_1%2C%201%2C%20u%20-%20t)%2C%20%5Cquad%20(q_1%2C%201%2C%202v%20%2B%20w%20-%20t)%20%5Cin%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%2C%20%5Cquad%20p_1%20%2B%20q_1%20%5Cleq%201%2C%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20(p_2%2C%201%2C%200.5u%20%2B%20%5Clog(0.1))%2C%20%5Cquad%20(q_2%2C%201%2C%20-v%20%2B%20%5Clog(2))%20%5Cin%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%2C%20%5Cquad%20p_2%20%2B%20q_2%20%5Cleq%201%2C%0A%20%20%20%20%20%20%20%20%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20(p_3%2C%201%2C%20-w)%2C%20%5Cquad%20(q_3%2C%201%2C%20v%20-%202u)%20%5Cin%20%5Cmathcal%7BK%7D_%7B%5Cexp%7D%2C%20%5Cquad%20p_3%20%2B%20q_3%20%5Cleq%201.%0A%20%20%20%20%20%20%20%20%5C%5D%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%208.%20Summary%20of%20Variable%20Domains%0A%0A%20%20%20%20%20%20%20%20%7C%20Symbol%20%7C%20Meaning%20%7C%20Domain%20%7C%0A%20%20%20%20%20%20%20%20%7C--------%7C---------%7C--------%7C%0A%20%20%20%20%20%20%20%20%7C%20%5C(%20x%20%5C)%20%7C%20Original%20decision%20variables%20%7C%20%5C(%20%5Cmathbb%7BR%7D_%7B%2B%7D%5En%20%5C)%20%7C%0A%20%20%20%20%20%20%20%20%7C%20%5C(%20y%20%5C)%20%7C%20Log-transformed%20variables%20%5C(%20y%20%3D%20%5Clog%20x%20%5C)%20%7C%20%5C(%20%5Cmathbb%7BR%7D%5En%20%5C)%20%7C%0A%20%20%20%20%20%20%20%20%7C%20%5C(%20c_k%20%5C)%20%7C%20Monomial%2Fposynomial%20coefficients%20%7C%20%5C(%20%5Cmathbb%7BR%7D_%7B%2B%7D%20%5C)%20%7C%0A%20%20%20%20%20%20%20%20%7C%20%5C(%20a_k%20%5C)%20%7C%20Monomial%20exponents%20%7C%20%5C(%20%5Cmathbb%7BR%7D%5En%20%5C)%20%7C%0A%20%20%20%20%20%20%20%20%7C%20%5C(%20t%20%5C)%20%7C%20Scalar%20upper%20bound%20variable%20%7C%20%5C(%20%5Cmathbb%7BR%7D%20%5C)%20%7C%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20References%0A%0A%20%20%20%20%20%20%20%20Some%20of%20the%20definitions%20used%20in%20this%20notebook%20are%20taken%20from%20the%20work%20%5BA%20Tutorial%20on%20Geometric%20Programming%5D(https%3A%2F%2Fstanford.edu%2F~boyd%2Fpapers%2Fpdf%2Fgp_tutorial.pdf)%20by%20Boyd%20et%20al.%0A%0A%20%20%20%20%20%20%20%20You%20can%20also%20read%20more%20about%20Geometric%20Programming%20and%20the%20example%20used%20in%20the%20%5BMOSEK%20Modeling%20Cookbook%5D(https%3A%2F%2Fdocs.mosek.com%2Fmodeling-cookbook%2Fexpo.html%23geometric-programming).%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%23Appendix%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20class%20definitions%2C%20used%20functions%20and%20model%20implementation%20can%20be%20examined%20below.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20mosek.fusion%20import%20Model%2C%20Domain%2C%20Expr%2C%20ObjectiveSense%0A%20%20%20%20import%20mosek.fusion.pythonic%0A%0A%20%20%20%20class%20Monomial%3A%0A%20%20%20%20%20%20%20%20def%20__init__(self%2C%20coefficient%3DNone%2C%20indices%3DNone%2C%20alphas%3DNone%2C%20n%3DNone)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.coefficient%20%3D%20coefficient%0A%20%20%20%20%20%20%20%20%20%20%20%20self.indices%20%3D%20indices%0A%20%20%20%20%20%20%20%20%20%20%20%20self.alphas%20%3D%20%5B0%5D%20*%20n%20if%20n%20is%20not%20None%20else%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20indices%20is%20not%20None%20and%20alphas%20is%20not%20None%20and%20n%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20idx%2C%20alpha%20in%20zip(indices%2C%20alphas)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.alphas%5Bidx%5D%20%3D%20alpha%0A%0A%20%20%20%20%20%20%20%20%40classmethod%0A%20%20%20%20%20%20%20%20def%20add(cls%2C%20coefficient%2C%20indices%2C%20alphas)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20obj%20%3D%20cls(coefficient%3Dcoefficient%2C%20indices%3Dindices%2C%20alphas%3DNone)%0A%20%20%20%20%20%20%20%20%20%20%20%20obj.indices_alphas%20%3D%20alphas%20%20%23%20Store%20original%20input%20to%20reconstruct%20later%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20obj%0A%0A%20%20%20%20%20%20%20%20def%20defineMonomial(self)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20terms%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20has_coefficient%20%3D%20self.coefficient%20!%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%2C%20alpha%20in%20enumerate(self.alphas)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20alpha%20!%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20terms.append(f%22(x_%7Bi%7D%20%5E%20%7Balpha%7D)%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20joined%20%3D%20%22%20*%20%22.join(%5Bf%22%7Bself.coefficient%7D%22%20if%20has_coefficient%20else%20%22%22%5D%20%2B%20terms%20if%20has_coefficient%20else%20terms)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20has_coefficient%20or%20len(terms)%20%3E%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20f%22(%7Bjoined.strip()%7D)%22%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20joined.strip()%0A%0A%20%20%20%20%20%20%20%20%40staticmethod%0A%20%20%20%20%20%20%20%20def%20definePosynomial(monomials)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%22%20%2B%20%22.join(%5Bm.defineMonomial()%20for%20m%20in%20monomials%5D)%0A%0A%20%20%20%20class%20GeometricProgramming%3A%0A%20%20%20%20%20%20%20%20def%20__init__(self%2C%20m%2C%20n)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20self.m%20%3D%20m%0A%20%20%20%20%20%20%20%20%20%20%20%20self.n%20%3D%20n%0A%20%20%20%20%20%20%20%20%20%20%20%20self.constraintsMonomials%20%3D%20%5B%5B%5D%20for%20_%20in%20range(m)%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20self.objectiveMonomials%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20self.totalMonomials%20%3D%200%0A%0A%20%20%20%20%20%20%20%20def%20_fillAlphas(self%2C%20monomial)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Check%20all%20alphas%20before%20assigning%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20alpha%20in%20monomial.indices_alphas%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20alpha%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(f%22Invalid%20alpha%20value%20%7Balpha%7D%3A%20all%20exponents%20must%20be%20non-zero.%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Safe%20to%20assign%20now%0A%20%20%20%20%20%20%20%20%20%20%20%20monomial.alphas%20%3D%20%5B0%5D%20*%20self.n%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20idx%2C%20alpha%20in%20zip(monomial.indices%2C%20monomial.indices_alphas)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20monomial.alphas%5Bidx%5D%20%3D%20alpha%0A%0A%20%20%20%20%20%20%20%20def%20_checkDuplicateIndex(self%2Cmonomial)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20seen%20%3D%20set()%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20idx%20in%20monomial.indices%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20idx%20in%20seen%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Input%20indices%20has%20to%20be%20unique.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20seen.add(idx)%0A%0A%20%20%20%20%20%20%20%20def%20addObjective(self%2C%20monomial)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20isinstance(monomial%2C%20list)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20m%20in%20monomial%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.addObjective(m)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20monomial.coefficient%20%3C%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Coefficient%20must%20be%20positive%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self._checkDuplicateIndex(monomial)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self._fillAlphas(monomial)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.objectiveMonomials.append(monomial)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.totalMonomials%20%2B%3D%201%0A%0A%20%20%20%20%20%20%20%20def%20addConstraint(self%2C%20index%2C%20monomial)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20index%20%3E%3D%20self.m%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(f%22Constraint%20index%20%7Bindex%7D%20out%20of%20range%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20isinstance(monomial%2C%20list)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20m%20in%20monomial%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.addConstraint(index%2C%20m)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20monomial.coefficient%20%3C%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Coefficient%20must%20be%20positive%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self._checkDuplicateIndex(monomial)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self._fillAlphas(monomial)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.totalMonomials%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20self.constraintsMonomials%5Bindex%5D.append(monomial)%0A%0A%20%20%20%20%20%20%20%20def%20evaluateObjective(self%2C%20x_values)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(x_values)%20!%3D%20self.n%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(f%22x_values%20length%20%7Blen(x_values)%7D%20does%20not%20match%20problem%20dimension%20%7Bself.n%7D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20objective_val%20%3D%200.0%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20mon%20in%20self.objectiveMonomials%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20term%20%3D%20mon.coefficient%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20i%2C%20alpha%20in%20enumerate(mon.alphas)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20term%20*%3D%20x_values%5Bi%5D%20**%20alpha%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20objective_val%20%2B%3D%20term%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20objective_val%0A%0A%20%20%20%20%20%20%20%20def%20analyse(self)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22---------%20Model%20Analysis%20---------%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22%23%20of%20constraints%3A%20%22%2C%20self.m)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22%23%20of%20variables%3A%20%22%2C%20self.n)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20all_monomials%20%3D%20self.objectiveMonomials%20%2B%20%5Bm%20for%20sublist%20in%20self.constraintsMonomials%20for%20m%20in%20sublist%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20coefficients%20%3D%20%5Bmon.coefficient%20for%20mon%20in%20all_monomials%5D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20coefficients%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Range%20of%20coefficients%3A%20%5B%7Bmin(coefficients)%7D%2C%20%7Bmax(coefficients)%7D%5D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22No%20monomials%20added%20yet.%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20all_alphas%20%3D%20%5Babs(alpha)%20for%20mon%20in%20all_monomials%20for%20alpha%20in%20mon.alphas%20if%20alpha%20!%3D%200%5D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20all_alphas%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Range%20of%20absolute%20alpha%20values%3A%20%5B%7Bmin(all_alphas)%7D%2C%20%7Bmax(all_alphas)%7D%5D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22No%20alpha%20values%20found.%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Degree%20of%20Difficulty%3A%20%22%2C%20self.totalMonomials%20-%20self.n%20-%201%2C%20%22%5Cn%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%20in%20range(self.n)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20signs%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20mon%20in%20all_monomials%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alpha%20%3D%20mon.alphas%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20alpha%20%3E%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20signs.append(1)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20alpha%20%3C%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20signs.append(-1)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20signs%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20all(s%20%3E%200%20for%20s%20in%20signs)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Warning%3A%20Variable%20x_%7Bi%7D%20only%20has%20positive%20exponents%20across%20all%20monomials.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20all(s%20%3C%200%20for%20s%20in%20signs)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Warning%3A%20Variable%20x_%7Bi%7D%20only%20has%20negative%20exponents%20across%20all%20monomials.%22)%0A%0A%20%20%20%20%20%20%20%20def%20printModel(self)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Objective%20function%3A%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%5CtMinimize%3A%20%7BMonomial.definePosynomial(self.objectiveMonomials)%7D%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20any(self.constraintsMonomials)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22%5CnConstraints%3A%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20i%2C%20con%20in%20enumerate(self.constraintsMonomials)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20con%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(f%22%5CtConstraint%20%7Bi%2B1%7D%3A%20%7BMonomial.definePosynomial(con)%7D%20%3C%3D%201%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22%5CnNo%20constraints%20defined.%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22%20%22)%0A%0A%20%20%20%20%20%20%20%20def%20Solve(self%2C%20fileName%3DNone)%3A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20self.objectiveMonomials%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22No%20objective%20monomials%20defined.%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20M%20%3D%20Model()%0A%20%20%20%20%20%20%20%20%20%20%20%20x%20%3D%20M.variable(%22x%22%2C%20self.n)%0A%20%20%20%20%20%20%20%20%20%20%20%20t%20%3D%20M.variable(%22t%22%2C%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20p%20%3D%20M.variable(%22p%22%2C%20self.totalMonomials)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20currentMonomialIndex%20%3D%200%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Objective%0A%20%20%20%20%20%20%20%20%20%20%20%20dummySum%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20objectiveMonomials%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20noOfMono%20%3D%20len(self.objectiveMonomials)%0A%20%20%20%20%20%20%20%20%20%20%20%20j%20%3D%200%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20noOfMono%20%3E%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20mon%20in%20self.objectiveMonomials%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20expr%20%3D%20Expr.dot(mon.alphas%2C%20x.T)%20%2B%20np.log(mon.coefficient)%20-%20t%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20objectiveMonomials.append(expr)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dummySum.append(p%5BcurrentMonomialIndex%20%2B%20j%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20j%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(%22Objective%20Definition%22%2C%20Expr.hstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20p.slice(currentMonomialIndex%2C%20currentMonomialIndex%20%2B%20noOfMono)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.ones(noOfMono)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.vstack(objectiveMonomials))%20%3D%3D%20Domain.inPExpCone())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(%22Objective%20Dummy%20Sum%22%2C%20Expr.sum(Expr.vstack(dummySum))%20%3C%3D%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(%22Objective%20Definition%22%2C%20Expr.dot(self.objectiveMonomials%5B0%5D.alphas%2C%20x.T)%20%3C%3D%20t)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20currentMonomialIndex%20%2B%3D%20noOfMono%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20Constraints%20(only%20if%20defined)%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%2C%20monomials%20in%20enumerate(self.constraintsMonomials)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20monomials%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%20%20%23%20Skip%20empty%20constraint%20slots%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20noOfMono%20%3D%20len(monomials)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20constraintMonomials%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dummySum%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20j%20%3D%200%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20noOfMono%20%3E%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20mon%20in%20monomials%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20expr%20%3D%20Expr.dot(mon.alphas%2C%20x.T)%20%2B%20np.log(mon.coefficient)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20constraintMonomials.append(expr)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dummySum.append(p%5BcurrentMonomialIndex%20%2B%20j%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20j%20%2B%3D%201%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(%22Conic-Constraint%20Definition%22%20%2B%20str(i)%2C%20Expr.hstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20p.slice(currentMonomialIndex%2C%20currentMonomialIndex%20%2B%20noOfMono)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.ones(noOfMono)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Expr.vstack(constraintMonomials))%20%3D%3D%20Domain.inPExpCone())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(%22Constraint%20Dummy%20Sum%22%20%2B%20str(i)%2C%20Expr.sum(Expr.vstack(dummySum))%20%3C%3D%201)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(%22Constraint%20Definition%22%20%2B%20str(i)%2C%20Expr.dot(monomials%5B0%5D.alphas%2C%20x.T)%20%2B%20np.log(monomials%5B0%5D.coefficient)%20%3C%3D%200)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20currentMonomialIndex%20%2B%3D%20noOfMono%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20M.objective(%22Objective%20Function%22%2C%20ObjectiveSense.Minimize%2C%20t)%0A%20%20%20%20%20%20%20%20%20%20%20%20M.solve()%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20fileName%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M.writeTask(fileName%20%2B%20%22.ptf%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20ModelStatus%20%3D%20M.getPrimalSolutionStatus()%0A%20%20%20%20%20%20%20%20%20%20%20%20ProblemStatus%20%3D%20M.getProblemStatus()%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20ModelStatus%20%3D%3D%20mosek.fusion.pythonic.SolutionStatus.Optimal%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sol%20%3D%20x.level()%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20vars%20%3D%20np.exp(sol)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22Model%20Status%3A%20Optimal%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sol%20%3D%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20vars%20%3D%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22The%20problem%20does%20not%20have%20an%20optimal%20solution.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22Problem%20Status%3A%20%22%2C%20ProblemStatus)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20sol%2C%20vars%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Domain%2C%0A%20%20%20%20%20%20%20%20Expr%2C%0A%20%20%20%20%20%20%20%20GeometricProgramming%2C%0A%20%20%20%20%20%20%20%20Model%2C%0A%20%20%20%20%20%20%20%20Monomial%2C%0A%20%20%20%20%20%20%20%20ObjectiveSense%2C%0A%20%20%20%20%20%20%20%20mosek%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
54f48fae1daf123500087e524adb872813500d6f117ff69a1f07984227dc7308