print ' xtol = ', self.xtol print ' n = ', self.n print ' stp = ', self.stp print ' maxfev = ', self.maxfev self.info = info return if __name__ == '__main__': import amplpy import numpy from math import sqrt import sys nlp = amplpy.AmplModel(sys.argv[1]) f = nlp.obj(nlp.x0) g = nlp.grad(nlp.x0) d = -g SWLS = StrongWolfeLineSearch(f, nlp.x0, g, d, lambda z: nlp.obj(z), lambda z: nlp.grad(z), stp = 1.0/sqrt(numpy.dot(g,g))) print ' Before search' print ' f = ', f print ' stpmax = ', SWLS.stpmax SWLS.search() print ' After search'
def parse_cmdline(arglist): if len(arglist) != 1: commandline_err( 'I am hungry for an NL file\n\t Try ./pycpre filename.nl.') return None try: options, fname = getopt.getopt(arglist, '') except getopt.error, e: commandline_err("%s" % str(e)) return None return fname[0] ProblemName = parse_cmdline(sys.argv[1:]) nlp = amplpy.AmplModel(ProblemName, opts=1) xl = nlp.Lvar.tolist() xu = nlp.Uvar.tolist() gl = nlp.Lcon.tolist() gu = nlp.Ucon.tolist() x0 = nlp.x0.tolist() pi0 = nlp.pi0.tolist() m = nlp.m n = nlp.n nnzj = nlp.nnzj nnzh = nlp.nnzh def eval_f(x, user_data=None):