File: SolveProblem.java

package info (click to toggle)
coinor-ipopt 3.14.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,796 kB
  • sloc: cpp: 97,169; sh: 4,802; ansic: 2,537; java: 1,289; makefile: 821; fortran: 224; xml: 210
file content (70 lines) | stat: -rw-r--r-- 1,901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* Copyright (C) 2007 VRTech Industrial Technologies - www.vrtech.com.br.
 * Copyright (C) 2007 Tong Kewei, Beihang University, - www.buaa.edu.cn.
 * All Rights Reserved.
 * This code is published under the Eclipse Public License.
 */

import java.util.HashMap;
import org.coinor.Ipopt;

/** Class for running several different Scalable problems.
 *
 * @author Rafael de Pelegrini Soares, Tong Kewei
 */
public class SolveProblem
{
   public static void main(
      String[] args)
   {
      HashMap<String, Scalable> list = new HashMap<String, Scalable>();

      // adding all problems here
      list.put("LukVlE1", new LuksanVlcek1("LukVlE1", 0.0, 0.0));// E means equal
      list.put("LukVlI1", new LuksanVlcek1("LukVlI1", -1.0, 0.0));// I means inequal

      if( args.length < 2 )
      {
         System.out.println("Usage: ProblemName N\n");
         System.out.println("  - N is a positive parameter determining problem size");
         System.out.println("  - ProblemName is one of:");
         // list all problems
         for( Scalable s : list.values() )
         {
            System.out.println("       " + s);
         }

         return;
      }

      String problem = args[0];
      int n = Integer.parseInt(args[1]);

      System.out.println("Solving problem " + problem + " for N=" + n);

      Scalable p = list.get(problem);
      if( p == null )
      {
         System.out.println("Problem not found!");
         return;
      }

      if( !p.initialize(n) )
      {
         return;
      }

      p.create();

      p.OptimizeNLP();

      switch( p.getStatus() )
      {
         case Ipopt.SOLVE_SUCCEEDED:
         case Ipopt.ACCEPTABLE_LEVEL:
            System.out.println("Solution found.");
            break;
         default:
            System.out.println("** Could not solve problem " + problem + " for N=" + n + ", status: " + p.getStatus());
      }
   }
}