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) 2020 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:`DummyConstraint`.""" 

20 

21from collections import namedtuple 

22 

23from ..apidoc import api_end, api_start 

24from ..caching import cached_property 

25from .constraint import ConicConstraint 

26 

27_API_START = api_start(globals()) 

28# ------------------------------- 

29 

30 

31class DummyConstraint(ConicConstraint): 

32 """An explicit way to *not* put a bound on an affine expression. 

33 

34 This is produced when declaring an expression a member of the trivial 

35 :class:`~.expressions.TheField` cone. 

36 

37 A constraint of this type can be used to pass a variable to a solver that 

38 does not otherwise appear in the problem. 

39 """ 

40 

41 def __init__(self, x): 

42 """Construct a :class:`DummyConstraint`.""" 

43 from ..expressions import ComplexAffineExpression 

44 

45 assert isinstance(x, ComplexAffineExpression) 

46 

47 self.x = x 

48 

49 super(DummyConstraint, self).__init__("Dummy") 

50 

51 @cached_property 

52 def conic_membership_form(self): 

53 """Implement for :class:`~.constraint.ConicConstraint`.""" 

54 from ..expressions import TheField 

55 return self.x.vec, TheField(dim=len(self.x)) 

56 

57 Subtype = namedtuple("Subtype", ()) 

58 

59 def _subtype(self): 

60 return self.Subtype() 

61 

62 @classmethod 

63 def _cost(cls, subtype): 

64 return 0 

65 

66 def _expression_names(self): 

67 yield "x" 

68 

69 def _str(self): 

70 return "{} is {}".format( 

71 self.x.string, "complex" if self.x.complex else "real") 

72 

73 def _get_size(self): 

74 return (len(self.x), 1) 

75 

76 def _get_slack(self): 

77 return 0 

78 

79 

80# -------------------------------------- 

81__all__ = api_end(_API_START, globals())