示例#1
0
  def testSpecificProblemDimTwo(self):
    """
    A specific problem of dimension two has been choosen to be tested.
    """

    # prepare set of testing cases
    f = {(0, 0): 5, (1, 0): -2, (2, 0): 1, (0, 1): -4, (0, 2): 1}
    g = {(0, 0): 3**2, (0, 2): -1, (2, 0): -1}
    solution = matrix([[1], [2]])

    # test all cases
    for degree in range(1, 3):
      with self.subTest(i = degree):
        # init prolem
        problem = POPSolver(f, g, degree)

        # solve and compare the results
        x = problem.solve(problem.getFeasiblePoint(3))
        self.assertLessEqual(norm(x - solution), 10**(-3))
示例#2
0
from numpy import *
from POPSolver import POPSolver

# objective function
# f(x, y) = (x - 1)^2 + (y - 2)^2
#         = x^2 -2*x + y^2 - 4*y + 5
# global minima at (1, 2)
f = {(0, 0): 5, (1, 0): -2, (2, 0): 1, (0, 1): -4, (0, 2): 1}

# constraint function
# g(x, y) = 9 - x^2 - y^2
g = {(0, 0): 3**2, (2, 0): -1, (0, 2): -1}

# degree of the relaxation
d = 2

# initialize the solver
POP = POPSolver(f, g, d)

# obtain some feasible point for the SDP problem (within ball with radius 3)
y0 = POP.getFeasiblePoint(3)

# enable outputs
POP.setPrintOutput(True)

#solve the problem
x = POP.solve(y0)
print(x)

示例#3
0
    minD = int(ceil(dF/2))

    # for relaxation order
    for dR in order:
      d = dR + minD

      # clear measured time
      t = 0

      # for different feasible points
      for i in N:
        # startup time
        timeStart = timeit.default_timer()

        # initialize the solver
        problem = POPSolver(f, g, d)

        # obtain some feasible point for the SDP problem
        y0 = problem.getFeasiblePoint(1)

        #solve the problem
        problem.solve(y0)

        # final time
        t += timeit.default_timer() - timeStart

      print((n, dF, dR))
      results[n, dF, dR] = t/len(N)

save('performanceResults/performanceResults.npy', results)
print(results)