Skip to content

Commit d27111e

Browse files
committed
Error if incomplete
1 parent 34bd9ec commit d27111e

File tree

2 files changed

+146
-42
lines changed

2 files changed

+146
-42
lines changed

src/soplex/spxlpbase_rational.hpp

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,11 @@ bool SPxLPBase<Rational>::readLPF(
572572
int sense = 0;
573573

574574
int lineno = 0;
575+
int initial;
575576
bool unnamed = true;
576577
bool finished = false;
577578
bool other;
578-
bool have_value = true;
579+
bool have_value = false;
579580
int i;
580581
int k;
581582
int buf_size;
@@ -662,7 +663,10 @@ bool SPxLPBase<Rational>::readLPF(
662663
}
663664

664665
if(finished)
666+
{
667+
finished = !have_value;
665668
break;
669+
}
666670

667671
if((size_t) buf_size > sizeof(tmp))
668672
{
@@ -685,11 +689,17 @@ bool SPxLPBase<Rational>::readLPF(
685689
{
686690
if(LPFhasKeyword(pos, "max[imize]"))
687691
{
692+
if(have_value)
693+
goto syntax_error;
694+
688695
changeSense(SPxLPBase<Rational>::MAXIMIZE);
689696
section = OBJECTIVE;
690697
}
691698
else if(LPFhasKeyword(pos, "min[imize]"))
692699
{
700+
if(have_value)
701+
goto syntax_error;
702+
693703
changeSense(SPxLPBase<Rational>::MINIMIZE);
694704
section = OBJECTIVE;
695705
}
@@ -701,14 +711,15 @@ bool SPxLPBase<Rational>::readLPF(
701711
|| LPFhasKeyword(pos, "s[.][ ]t[.]")
702712
|| LPFhasKeyword(pos, "lazy con[straints]"))
703713
{
714+
if(have_value)
715+
goto syntax_error;
716+
704717
// store objective vector
705718
for(int j = vec.size() - 1; j >= 0; --j)
706719
cset.maxObj_w(vec.index(j)) = vec.value(j);
707720

708721
// multiplication with -1 for minimization is done below
709722
vec.clear();
710-
have_value = true;
711-
val = 1;
712723
section = CONSTRAINTS;
713724
}
714725
}
@@ -717,40 +728,63 @@ bool SPxLPBase<Rational>::readLPF(
717728
|| LPFhasKeyword(pos, "s[uch][ ]t[hat]")
718729
|| LPFhasKeyword(pos, "s[.][ ]t[.]")))
719730
{
720-
have_value = true;
721-
val = 1;
731+
if(have_value)
732+
goto syntax_error;
722733
}
723734
else
724735
{
725736
if(LPFhasKeyword(pos, "lazy con[straints]"))
726-
;
737+
{
738+
if(have_value)
739+
goto syntax_error;
740+
}
727741
else if(LPFhasKeyword(pos, "bound[s]"))
742+
{
743+
if(have_value)
744+
goto syntax_error;
745+
728746
section = BOUNDS;
747+
}
729748
else if(LPFhasKeyword(pos, "bin[ary]"))
749+
{
750+
if(have_value)
751+
goto syntax_error;
752+
730753
section = BINARIES;
754+
}
731755
else if(LPFhasKeyword(pos, "bin[aries]"))
756+
{
757+
if(have_value)
758+
goto syntax_error;
759+
732760
section = BINARIES;
761+
}
733762
else if(LPFhasKeyword(pos, "gen[erals]"))
763+
{
764+
if(have_value)
765+
goto syntax_error;
766+
734767
section = INTEGERS;
768+
}
735769
else if(LPFhasKeyword(pos, "int[egers]")) // this is undocumented
770+
{
771+
if(have_value)
772+
goto syntax_error;
773+
736774
section = INTEGERS;
775+
}
737776
else if(LPFhasKeyword(pos, "end"))
738777
{
739-
finished = true;
778+
finished = !have_value;
740779
break;
741780
}
742781
else if(LPFhasKeyword(pos, "s[ubject][ ]t[o]") // second time
743782
|| LPFhasKeyword(pos, "s[uch][ ]t[hat]")
744783
|| LPFhasKeyword(pos, "s[.][ ]t[.]")
745784
|| LPFhasKeyword(pos, "lazy con[straints]"))
746785
{
747-
// In principle this has to checked for all keywords above,
748-
// otherwise we just ignore any half finished constraint
749786
if(have_value)
750787
goto syntax_error;
751-
752-
have_value = true;
753-
val = 1;
754788
}
755789
}
756790

@@ -796,6 +830,7 @@ bool SPxLPBase<Rational>::readLPF(
796830
//--- Line processing loop
797831
//-----------------------------------------------------------------------
798832
pos = line;
833+
initial = true;
799834

800835
SPxOut::debug(spxout, "DLPFRD09 pos= {}\n", pos);
801836

@@ -828,21 +863,31 @@ bool SPxLPBase<Rational>::readLPF(
828863
have_value = true;
829864
val = LPFreadValue(pos, spxout, lineno);
830865
val *= pre_sign;
831-
}
832866

833-
if(!have_value)
834-
goto syntax_error;
867+
/* continue next line with sign */
868+
if(*pos == '\0' && (*(pos - 1) == '+' || *(pos - 1) == '-'))
869+
continue;
870+
}
835871

836-
if(*pos == '\0')
872+
if(!have_value && initial)
873+
val = 1.0;
874+
else
837875
{
838-
changeObjOffset(val);
839-
continue;
876+
if(!have_value)
877+
goto syntax_error;
878+
879+
have_value = false;
880+
881+
if(*pos == '\0')
882+
{
883+
changeObjOffset(val);
884+
break;
885+
}
840886
}
841887

842888
if(!LPFisColName(pos))
843889
goto syntax_error;
844890

845-
have_value = false;
846891
colidx = LPFreadColName(pos, cnames, cset, &emptycol, spxout);
847892
vec.add(colidx, val);
848893
break;
@@ -901,7 +946,7 @@ bool SPxLPBase<Rational>::readLPF(
901946
rnames->add(name);
902947
}
903948

904-
have_value = true;
949+
have_value = false;
905950
val = 1;
906951
sense = 0;
907952
pos = nullptr;
@@ -910,7 +955,12 @@ bool SPxLPBase<Rational>::readLPF(
910955
}
911956
}
912957

913-
if(*pos == '\0')
958+
if(!have_value && initial)
959+
{
960+
have_value = true;
961+
val = 1;
962+
}
963+
else if(*pos == '\0')
914964
continue;
915965

916966
if(have_value)
@@ -1087,6 +1137,8 @@ bool SPxLPBase<Rational>::readLPF(
10871137

10881138
if(pos == pos_old)
10891139
goto syntax_error;
1140+
1141+
initial = false;
10901142
}
10911143
}
10921144

0 commit comments

Comments
 (0)