|
22 | 22 | December 2010: Modified for SciPy
|
23 | 23 | """
|
24 | 24 |
|
25 |
| -__all__= ['readproblem','writeproblem','fromsdpa','tosdpa'] |
| 25 | +__all__= ['readproblem','writeproblem','fromsdpa','tosdpa','importsdpa','exportsdpa'] |
26 | 26 |
|
27 | 27 | from .importconvert
|
28 | 28 | from .symconeimportSymCone
|
29 | 29 | fromscipy.sparseimportcsc_matrix,csr_matrix
|
30 | 30 | fromscipyimportsparse
|
| 31 | +importwarnings |
31 | 32 |
|
32 | 33 |
|
33 | 34 | defreadproblem(filename):
|
@@ -267,7 +268,7 @@ def writeproblem(filename, A, b, c, K, J, accuracy="%+8.16e"):
|
267 | 268 | return
|
268 | 269 |
|
269 | 270 |
|
270 |
| -deffromsdpa(filename): |
| 271 | +defimportsdpa(filename,flipsign=True): |
271 | 272 | """Convert from SDPA sparse format to CLP format
|
272 | 273 |
|
273 | 274 | Args:
|
@@ -452,10 +453,15 @@ def fromsdpa(filename):
|
452 | 453 | A=csc_matrix((elements_A[2], (elements_A[0],elements_A[1])),
|
453 | 454 | shape=(J.f,size_K))
|
454 | 455 |
|
| 456 | +ifflipsign: |
| 457 | +c=-c |
| 458 | +b=-b |
| 459 | +A=-A |
| 460 | + |
455 | 461 | returnA,b,c,K,J
|
456 | 462 |
|
457 | 463 |
|
458 |
| -deftosdpa(filename,A,b,c,K,J,accuracy="%+8.16e"): |
| 464 | +defexportsdpa(filename,A,b,c,K,J,accuracy="%+8.16e",flipsign=True): |
459 | 465 | """Convert from SeDuMi format to SDPA sparse format
|
460 | 466 |
|
461 | 467 | If J.l or J.q or J.s are not empty, CLP format will be converted
|
@@ -489,11 +495,14 @@ def tosdpa(filename, A, b, c, K, J, accuracy="%+8.16e"):
|
489 | 495 | # Note that primal-dual is reverse in SeDuMi.
|
490 | 496 | # So c2 must be -c2.
|
491 | 497 | # In addition, A2 should be passed in the transposed style.
|
492 |
| -# December 2023 edit: to maintain consistency with `writeproblem` method |
493 |
| -# (that exports to CLP format) this sign flipping is being omitted here. |
494 |
| -c2=c |
495 |
| -b2=b |
496 |
| -A2=A |
| 498 | +ifflipsign: |
| 499 | +c2=-c |
| 500 | +b2=-b |
| 501 | +A2=-A |
| 502 | +else: |
| 503 | +c2=c |
| 504 | +b2=b |
| 505 | +A2=A |
497 | 506 |
|
498 | 507 | fp=open(filename,"w")
|
499 | 508 |
|
@@ -670,6 +679,30 @@ def tosdpa(filename, A, b, c, K, J, accuracy="%+8.16e"):
|
670 | 679 | return
|
671 | 680 |
|
672 | 681 |
|
| 682 | +# retaining them for backward compatibility |
| 683 | + |
| 684 | +deffromsdpa(filename): |
| 685 | +warnings.warn("fromsdpa will be removed in the future. " |
| 686 | +"Please use importsdpa.",DeprecationWarning,stacklevel=2) |
| 687 | +A,b,c,K,J=importsdpa(filename,flipsign=False) |
| 688 | +returnA,b,c,K,J |
| 689 | + |
| 690 | +deftosdpa(filename,A,b,c,K,J,accuracy="%+8.16e"): |
| 691 | +warnings.warn("tosdpa will be removed in the future. " |
| 692 | +"Please use exportsdpa.",DeprecationWarning,stacklevel=2) |
| 693 | + |
| 694 | +# Note that with flipsign=True, this is identical to the exportsdpa routine |
| 695 | +# that replaces it (i.e. does not require flipping sign of A, b, c). |
| 696 | +exportsdpa(filename,A,b,c,K,J,accuracy="%+8.16e",flipsign=True) |
| 697 | + |
| 698 | +# Reason for deprecating this (and the accompanying fromsdpa routine): |
| 699 | +# tosdpa did not require sign flipping (while fromsdpa required manual |
| 700 | +# sign flipping). This was confusing to the user. |
| 701 | + |
| 702 | +# The new importsdpa and exportsdpa routines both perform sign |
| 703 | +# flipping by default which is intuitive to most users. |
| 704 | + |
| 705 | + |
673 | 706 | # ==================================================
|
674 | 707 | # Functions to write result file
|
675 | 708 | # ==================================================
|
|