void MPS_ROWS() { if (strncmp(Buf, "ROWS", 4)) CheckError(1, "MPS_ROWS: Expected ROWS!"); printf(" ROWS SECTION\n"); while (1) { MPS_ReadLine(); if (Buf[0] != ' ') // End of ROWS break; char Type = toupper(Buf[1]); if (Type == ' ') Type = toupper(Buf[2]); if (Type != 'N' && Type != 'E' && Type != 'G' && Type != 'L') { printf(" Warning: Unknown Type: \"%c\", Ignored.\n", Type); continue; } unsigned long long Hash = MPS_HashCode(Buf + CARD_POS[0]); if (Type == 'N') { if (Obj_Row) { printf(" Warning: Duplicate Objective Row, Ignored.\n"); continue; } Obj_Row = Hash; // Store Objective Row's Hash Value Hash_Row.Insert(Hash, HASH_OBJECTIVE); // Objective continue; } if (Hash_Row.Insert(Hash, n_Row) == HASH_INSERT_FOUND) { printf(" Warning: Duplicate Row Name, HashCode = %llu, Ignored.\n", Hash); continue; } Row_Type[n_Row] = Type; V_RHS[n_Row] = 0.0; n_Row ++; } printf(" %d Rows Read (Objective Row Excluded)\n", n_Row); if (! Obj_Row) CheckError(1, "MPS_ROWS: No Objective Row!"); }
void MPS_COLUMNS() { if (strncmp(Buf, "COLUMNS", 7)) CheckError(1, "MPS_COLUMNS: Expected COLUMNS!"); printf(" COLUMNS SECTION\n"); ColItemNo = 0; while (1) { ColItemNo ++; MPS_ReadLine(); if (Buf[0] != ' ') // End of COLUMNS break; unsigned long long ColHash = MPS_HashCode(Buf + CARD_POS[0]); int ColID = Hash_Col.Find(ColHash); if (ColID == HASH_NOT_FOUND) { Hash_Col.Insert(ColHash, n_Col); ColID = n_Col; V_Cost[n_Col] = 0.0; V_Matrix_Col_Head[n_Col] = -1; n_Col ++; } int CurCardLen = strlen(Buf); for (int ip = 1; ip <= 3 && CARD_POS[ip] < CurCardLen; ip += 2) { unsigned long long RowHash = MPS_HashCode(Buf + CARD_POS[ip]); int RowID = Hash_Row.Find(RowHash); if (RowID == HASH_NOT_FOUND) { printf(" Warning: Row Name Not Found, HashCode = %llu, Ignored.\n", RowHash); continue; } double RCValue = atof(Buf + CARD_POS[ip + 1]); if (RowID == HASH_OBJECTIVE) // Objective, Minimization { V_Cost[ColID] = RCValue; continue; } if (fabs(RCValue) < Input_Tolerance) { printf(" Warning: Zero Element Found, %.10lf, Ignored.\n", RCValue); continue; } // Cannot check duplicate element V_Matrix_Row[n_Element] = RowID; V_Matrix_Value[n_Element] = RCValue; V_Matrix_Col_Next[n_Element] = V_Matrix_Col_Head[ColID]; V_Matrix_Col_Head[ColID] = n_Element; n_Element ++; } } printf(" %d Columns and %d Elements Read (Objective Row Excluded)\n", n_Col, n_Element); }