@@ -326,7 +326,7 @@ typedef struct
326326 char * objective_row_name ;
327327 char * current_col_name ;
328328 double objective_constant ;
329- bool is_maximize ;
329+ objective_sense_t objective_sense ;
330330 int error_flag ;
331331
332332} MpsParserState ;
@@ -454,25 +454,28 @@ lp_problem_t *read_mps_file(const char *filename)
454454 next_section = SEC_ENDATA ;
455455 }
456456
457- if (current_section == SEC_ROWS && next_section != SEC_ROWS && ! rows_finalized )
457+ if (next_section != SEC_NONE )
458458 {
459- if (finalize_rows (& state ) != 0 )
460- state .error_flag = 1 ;
461- rows_finalized = true;
462- }
459+ if (current_section == SEC_ROWS && next_section != SEC_ROWS && !rows_finalized )
460+ {
461+ if (finalize_rows (& state ) != 0 )
462+ state .error_flag = 1 ;
463+ rows_finalized = true;
464+ }
463465
464- current_section = next_section ;
465- if (current_section == SEC_ENDATA )
466- break ;
467- continue ;
466+ current_section = next_section ;
467+ if (current_section == SEC_ENDATA )
468+ break ;
469+ continue ;
470+ }
468471 }
469472
470473 switch (current_section )
471474 {
472475 case SEC_OBJSENSE :
473476 if (n_tokens > 0 && (strcmp (tokens [0 ], "MAX" ) == 0 || strcmp (tokens [0 ], "MAXIMIZE" ) == 0 ))
474477 {
475- state .is_maximize = true ;
478+ state .objective_sense = OBJECTIVE_SENSE_MAXIMIZE ;
476479 }
477480 break ;
478481 case SEC_ROWS :
@@ -515,7 +518,9 @@ lp_problem_t *read_mps_file(const char *filename)
515518 prob -> num_variables = state .col_map .size ;
516519 prob -> num_constraints = state .row_map .size ;
517520 prob -> constraint_matrix_num_nonzeros = state .coo_matrix .nnz ;
518- prob -> objective_constant = state .is_maximize ? - state .objective_constant : state .objective_constant ;
521+ prob -> objective_constant =
522+ (state .objective_sense == OBJECTIVE_SENSE_MAXIMIZE ) ? - state .objective_constant : state .objective_constant ;
523+ prob -> objective_sense = state .objective_sense ;
519524
520525 prob -> objective_vector = state .objective_coeffs ;
521526 prob -> variable_lower_bound = state .var_lower_bounds ;
@@ -532,7 +537,7 @@ lp_problem_t *read_mps_file(const char *filename)
532537 state .constraint_lower_bounds = NULL ;
533538 state .constraint_upper_bounds = NULL ;
534539
535- if (state .is_maximize )
540+ if (state .objective_sense == OBJECTIVE_SENSE_MAXIMIZE )
536541 {
537542 for (int i = 0 ; i < prob -> num_variables ; ++ i )
538543 {
0 commit comments