TransWikia.com

Setting up constraints in NMaximize

Mathematica Asked on March 21, 2021

I have an optimization problem for which I’m using NMaximize. For the constraints I need the variables to belong to a particular set.

{Subscript[x, i], Subscript[y, i], Subscript[z, i]} [Element] Table[Subscript[e, i, n], {i, 1, n}]

The Table provides the necessary 3-D points. Th problem is that NMaximize cant resolve these discrete set of points as a constraint. It outputs,

Unable to resolve the domain or region membership condition

What would be a possible workaround? I tried converting the points to a convex hull and defining that as a domain. But i have trouble doing so too. Thanks in advance.

EDIT: The complete code

Subscript[r, n_] := Sqrt[Sec[Pi/n]];
Subscript[w, i_,n_] := {Subscript[r, n] Cos[2 Pi i/n], 
Subscript[r, n] Sin[2 Pi i/n], 1};
Subscript[e, i_, n_] := 1/2 {Subscript[r, n] Cos[(2 i - 1) Pi/n], 
Subscript[r, n] Sin[(2 i - 1) Pi/n], 1};
Subscript[ex, i_, n_] := 1/2 {Subscript[r, n] Cos[(2 i - 1) Pi/n], 
Subscript[r, n] Sin[(2 i - 1) Pi/n]};
u = {0, 0, 1};
f = (u - #) &;
(*Factors={1,2,3,12,13,23,123}*)

Factors = Times @@@ Subsets[Transpose@Tuples[{1, -1}, 3], {1, 3}];
(*Rearrange*)
(*Rearrange the numbers in the RHS to obtain different combinations*)

Factors[[{1, 2, 3, 4, 5, 6, 7}]] = Factors[[{1, 2, 3, 4, 5, 6, 7}]];
Factors = Transpose[Factors];
Vec[j_] := {Subscript[x, j], Subscript[y, j], Subscript[z, j]};
AllParameters[k_] := 
Module[{i}, 
Flatten[Table[{Subscript[x, i], Subscript[y, i], Subscript[z,i]},{i, 1, k}]]];
AllConstraints[n_, k_] := 
Module[{i}, 
And @@ Table[{Subscript[x, i], Subscript[y, i]} [Element] 
   ConvexHullMesh[Table[Subscript[ex, i, n], {i, 1, n}]] && 
  Subscript[z, i] == 1/2, {i, 1, k}]];



GPT[n_, k_] := Module[{ro, co, ve, i},
FunFactor = Factors[[1 ;; 8, 1 ;; k]] /. {1 -> Identity, -1 -> f};
vec = Table[Subscript[v, i], {i, 1, k}] /. {Subscript[v, j_] -> Vec[j]};
vecs = Table[
Total[Table[FunFactor[[ro, co]][vec[[co]]], {co, 1, k}]], {ro, 1, 
 8}];
max = Total[
Table[Max[
  Map[vecs[[ve]].# &, Table[Subscript[w, i, n], {i, 1, n}]]], {ve, 1, 8}]];
out = NMaximize[{max, AllConstraints[n, k]}, AllParameters[k], 
MaxIterations -> 500, WorkingPrecision -> 50, 
AccuracyGoal -> Infinity, PrecisionGoal -> Infinity];
Print[out]; out[[1]]/(k 8)]

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP