示例#1
0
 def runTest(self):
     prob = 'ROSENBR'
     # Catch stdout
     # https://stackoverflow.com/questions/1218933/can-i-redirect-the-stdout-in-python-into-some-sort-of-string-buffer
     real_stdout = sys.stdout
     fake_stdout = io.StringIO()
     try:
         sys.stdout = fake_stdout
         # Now do the work
         pycutest.print_available_sif_params(prob)
     finally:
         sys.stdout = real_stdout
         output_string = fake_stdout.getvalue()
         fake_stdout.close()
         # Now can do checking
         print(output_string)
         # ROSENBR has no parameters available
         self.assertTrue(prob in output_string,
                         msg="Output missing problem name")
         output_string = output_string.replace(
             "Parameters available for problem %s:" % prob, "")
         output_string = output_string.replace(
             "End of parameters for problem %s" % prob, "")
         output_string = output_string.rstrip()
         print("***")
         print("'%s', %g" % (output_string, len(output_string)))
         print("***")
         self.assertEqual(len(output_string),
                          0,
                          msg="Some parameters found")
示例#2
0
    def runTest(self):
        prob = 'ARGLALE'
        # Catch stdout
        # https://stackoverflow.com/questions/1218933/can-i-redirect-the-stdout-in-python-into-some-sort-of-string-buffer
        real_stdout = sys.stdout
        fake_stdout = io.StringIO()
        try:
            sys.stdout = fake_stdout
            # Now do the work
            pycutest.print_available_sif_params(prob)
        finally:
            sys.stdout = real_stdout
            output_string = fake_stdout.getvalue()
            fake_stdout.close()
            # Now can do checking
            print(output_string)
            """
            From ARGLALE.SIF:
            *IE N                   10             $-PARAMETER
            *IE N                   50             $-PARAMETER
            *IE N                   100            $-PARAMETER
             IE N                   200            $-PARAMETER

            *IE M                   20             $-PARAMETER .ge. N
            *IE M                   100            $-PARAMETER .ge. N
            *IE M                   200            $-PARAMETER .ge. N
             IE M                   400            $-PARAMETER .ge. N
            """
            self.assertTrue(prob in output_string,
                            msg="Output missing problem name")
            self.assertTrue("N = 10 (int)" in output_string,
                            msg="Missing option N=10")
            self.assertTrue("N = 50 (int)" in output_string,
                            msg="Missing option N=50")
            self.assertTrue("N = 100 (int)" in output_string,
                            msg="Missing option N=100")
            self.assertTrue("N = 200 (int) [default]" in output_string,
                            msg="Missing (default) option N=200")
            self.assertTrue("M = 20 (int, .ge. N)" in output_string,
                            msg="Missing option M=20")
            self.assertTrue("M = 100 (int, .ge. N)" in output_string,
                            msg="Missing option M=100")
            self.assertTrue("M = 200 (int, .ge. N)" in output_string,
                            msg="Missing option M=200")
            self.assertTrue("M = 400 (int, .ge. N) [default]" in output_string,
                            msg="Missing (default) option M=400")
示例#3
0
    def runTest(self):
        prob = 'BRATU2D'
        # Catch stdout
        # https://stackoverflow.com/questions/1218933/can-i-redirect-the-stdout-in-python-into-some-sort-of-string-buffer
        real_stdout = sys.stdout
        fake_stdout = io.StringIO()
        try:
            sys.stdout = fake_stdout
            # Now do the work
            pycutest.print_available_sif_params(prob)
        finally:
            sys.stdout = real_stdout
            output_string = fake_stdout.getvalue()
            fake_stdout.close()
            # Now can do checking
            print(output_string)
            """
            From BRATU2D.SIF:
            *IE P                   7              $-PARAMETER  n=P**2   original value
            *IE P                   10             $-PARAMETER  n=P**2
            *IE P                   22             $-PARAMETER  n=P**2
            *IE P                   32             $-PARAMETER  n=P**2
             IE P                   72             $-PARAMETER  n=P**2

            *   LAMBDA is the Bratu problem parameter.  It should be positive.

             RE LAMBDA              4.0            $-PARAMETER > 0
            """
            self.assertTrue(prob in output_string,
                            msg="Output missing problem name")
            self.assertTrue("P = 7 (int, n=P**2 original value)"
                            in output_string,
                            msg="Missing option P=7")
            self.assertTrue("P = 10 (int, n=P**2)" in output_string,
                            msg="Missing option P=10")
            self.assertTrue("P = 22 (int, n=P**2)" in output_string,
                            msg="Missing option P=22")
            self.assertTrue("P = 32 (int, n=P**2)" in output_string,
                            msg="Missing option P=32")
            self.assertTrue("P = 72 (int, n=P**2) [default]" in output_string,
                            msg="Missing (default) option P=72")
            self.assertTrue("LAMBDA = 4 (float, > 0) [default]"
                            in output_string,
                            msg="Missing (default) option LAMBDA=4")
示例#4
0
        'NONDQUAR': 100,
        'PENALTY1': 1000,
        'PENALTY3': 100,
        'QUARTC': 1000,
        'SINQUAD': 1000,
        'SROSENBR': 1000,
        'TQUARTIC': 1000,
        'TRIDIA': 1000
    }
else:
    problems = [problemName]
    Ns = {problemName: args.N}

#%% Print problem parameters and properties
if problemName != 'ALL' and problemName != 'L-BFGS':
    pycutest.print_available_sif_params(problemName)
    print(pycutest.problem_properties(problemName))
else:
    successes = []
    failures = []
    if (problemName == 'ALL'):
        failures.append('INDEF')

#%% For loop through all problems to solve
for problemName in sorted(problems):

    #%% Create instance of problem
    if problemName in Ns:
        sifParams = {'N': Ns[problemName]}
    else:
        sifParams = {}
#!/usr/bin/env python3
"""
Test interface for parameter-dependent problems
"""

# Ensure compatibility with Python 2
from __future__ import absolute_import, division, print_function, unicode_literals

import pycutest

# name = 'ARGLALE'
# name = 'COOLHANS'
name = 'SEMICON2'

pycutest.print_available_sif_params(name)