Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# ------------------------------------------------------------------------------ 

2# Copyright (C) 2017 Maximilian Stahlberg 

3# 

4# This file is part of PICOS. 

5# 

6# PICOS is free software: you can redistribute it and/or modify it under the 

7# terms of the GNU General Public License as published by the Free Software 

8# Foundation, either version 3 of the License, or (at your option) any later 

9# version. 

10# 

11# PICOS is distributed in the hope that it will be useful, but WITHOUT ANY 

12# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 

13# A PARTICULAR PURPOSE. See the GNU General Public License for more details. 

14# 

15# You should have received a copy of the GNU General Public License along with 

16# this program. If not, see <http://www.gnu.org/licenses/>. 

17# ------------------------------------------------------------------------------ 

18 

19"""Implementation of :class:`SMCPSolver`.""" 

20 

21# ------------------------------------------------------------------------------ 

22# This file is a skeleton implementation for the SMCP solver. 

23# Currently, the functional implementation is found in CVXOPTSolver. 

24# ------------------------------------------------------------------------------ 

25 

26from ..apidoc import api_end, api_start 

27from ..constraints import AffineConstraint, DummyConstraint, LMIConstraint 

28from ..expressions import CONTINUOUS_VARTYPES, AffineExpression 

29from ..modeling.footprint import Specification 

30from .solver import Solver 

31from .solver_cvxopt import CVXOPTSolver 

32 

33_API_START = api_start(globals()) 

34# ------------------------------- 

35 

36 

37class SMCPSolver(CVXOPTSolver): 

38 """Interface to the SMCP solver. 

39 

40 Most of the logic is implemented in the 

41 :class:`CVXOPTSolver <picos.solvers.solver_cvxopt.CVXOPTSolver>` base class. 

42 """ 

43 

44 SUPPORTED = Specification( 

45 objectives=[ 

46 AffineExpression], 

47 variables=CONTINUOUS_VARTYPES, 

48 constraints=[ 

49 DummyConstraint, 

50 AffineConstraint, 

51 # TODO: See below. 

52 # SOCConstraint, 

53 # RSOCConstraint, 

54 LMIConstraint]) 

55 

56 @classmethod 

57 def supports(cls, footprint, explain=False): 

58 """Implement :meth:`~.solver.Solver.supports`.""" 

59 result = Solver.supports(footprint, explain) 

60 if not result or (explain and not result[0]): 

61 return result 

62 

63 # TODO: SMCP formally supports problems that are not SDPs, but it is 

64 # known to perform poorly for them, sometimes even returning 

65 # incorrect solutions. For now, only support SDPs. 

66 if not ("con", LMIConstraint) in footprint: 

67 if explain: 

68 return False, "Problems other than SDPs (PICOS' choice)." 

69 else: 

70 return False 

71 

72 if footprint not in cls.SUPPORTED: 

73 if explain: 

74 return False, cls.SUPPORTED.mismatch_reason(footprint) 

75 else: 

76 return False 

77 

78 return (True, None) if explain else True 

79 

80 @classmethod 

81 def default_penalty(cls): 

82 """Implement :meth:`~.solver.Solver.default_penalty`.""" 

83 return 2.0 # Experimental free/open source solver. 

84 

85 @classmethod 

86 def test_availability(cls): 

87 """Implement :meth:`~.solver.Solver.test_availability`.""" 

88 cls.check_import("smcp") 

89 

90 @classmethod 

91 def names(cls): 

92 """Implement :meth:`~.solver.Solver.names`.""" 

93 return "smcp", "SMCP", "Sparse Matrix Cone Program Solver" 

94 

95 @classmethod 

96 def is_free(cls): 

97 """Implement :meth:`~.solver.Solver.is_free`.""" 

98 return True 

99 

100 @property 

101 def is_smcp(self): 

102 """Whether to implement SMCP instead of CVXOPT.""" 

103 return True 

104 

105 

106# -------------------------------------- 

107__all__ = api_end(_API_START, globals())