/// <summary> /// Obtains the amount of columns /// </summary> /// <param name="symbol"></param> /// <returns></returns> public int GetColumnCount(GAMSSymbol symbol) { int result = 0; switch (symbol) { case GAMSSet gset: // SET result = gset.Dim + 1; break; case GAMSParameter gparam: // PARAMETER result = gparam.Dim + 1 * 2; if (!string.IsNullOrEmpty(gparam.Text) && gparam.Dim == 0) { result++; } break; case GAMSEquation geq: case GAMSVariable gvar: // EQUATION AND VARIABLE result = symbol.Dim + 5 * 2; break; } return(result); }
/// <summary> /// Obtains the column's headers /// </summary> /// <param name="symbol"></param> /// <returns></returns> public List <Tuple <string, QvxFieldType> > GetColumnHeaders(GAMSSymbol symbol) { List <Tuple <string, QvxFieldType> > returnList = new List <Tuple <string, QvxFieldType> >(); // Dimensions GenerateDimensionColumnNames(symbol.DomainsAsStrings).ForEach(item => returnList.Add(new Tuple <string, QvxFieldType>(item, QvxFieldType.QVX_TEXT))); switch (symbol) { case GAMSSet gset: // SET returnList.Add(new Tuple <string, QvxFieldType>(TEXT, QvxFieldType.QVX_TEXT)); break; case GAMSParameter gparam: // PARAMETER returnList.Add(new Tuple <string, QvxFieldType>(VALUE, QvxFieldType.QVX_IEEE_REAL)); returnList.Add(new Tuple <string, QvxFieldType>(VALUE + SPECIAL_VALUE_SUFFIX, QvxFieldType.QVX_TEXT)); if (!string.IsNullOrEmpty(gparam.Text) && gparam.Dim == 0) { returnList.Add(new Tuple <string, QvxFieldType>("@Comments", QvxFieldType.QVX_TEXT)); } break; case GAMSEquation geq: case GAMSVariable gvar: // EQUATION AND VARIABLE string[] gms_labels = { LEVEL, MARGINAL, LOWER, UPPER, SCALE }; foreach (string label in gms_labels) { returnList.Add(new Tuple <string, QvxFieldType>(label, QvxFieldType.QVX_IEEE_REAL)); returnList.Add(new Tuple <string, QvxFieldType>(label + SPECIAL_VALUE_SUFFIX, QvxFieldType.QVX_TEXT)); } break; default: returnList = new List <Tuple <string, QvxFieldType> >(); break; } return(returnList); }
/// <summary> /// Obtains the preview data using the high level API /// </summary> /// <param name="tableName"></param> /// <param name="NumberOfRows"></param> /// <returns></returns> public string[,] GetPreviewData(QvxTable table, int NumberOfRows = int.MaxValue) { string[,] returnTable; GAMSSymbol symbol = Db.GetSymbol(table.TableName); switch (symbol) { case GAMSSet gset: GetPreviewColumnsData(out returnTable, gset, NumberOfRows); break; case GAMSParameter gparam: GetPreviewColumnsData(out returnTable, gparam, NumberOfRows); break; case GAMSEquation geq: GetPreviewColumnsData(out returnTable, geq, NumberOfRows); break; case GAMSVariable gvar: GetPreviewColumnsData(out returnTable, gvar, NumberOfRows); break; default: returnTable = new string[0, 0]; break; } int FinalNumberOfRows = returnTable.GetLength(0); int NumberOfColumns = returnTable.GetLength(1); //Using advanced api for retrieve acronyms if existing string msg = ""; int ErrNr = 0, SymNr = 0; using (gdxcs gdx = new gdxcs(ref msg)) { gdx.gdxOpenRead(GDXFileLocation, ref ErrNr); gdx.gdxFindSymbol(table.TableName, ref SymNr); int dimensions = symbol.Dim; for (int i = 0; i < FinalNumberOfRows; i++) { for (int j = dimensions; j < NumberOfColumns; j++) { if (double.TryParse(returnTable[i, j], out double doubleForParse)) { string value = val2str(doubleForParse, msg, out Boolean isSpecial); if (isSpecial) { // Values use two columns, and special values appear in the second one. So we increase the counter returnTable[i, j++] = ""; } returnTable[i, j] = value; } } } string val2str(double val, string s, out Boolean isSpecial) { string[] gmsSVText = { "UNdef", "NA", "+Inf", "-Inf", "Eps", "0", "AcroN" }; isSpecial = false; int sv = 0; if (gdx.gdxAcronymName(val, ref s) != 0) { isSpecial = true; return(s); } else { gdx.gdxMapValue(val, ref sv); if (gamsglobals.sv_normal != sv) { isSpecial = true; return(gmsSVText[sv]); } else { return(val.ToString("N", new CultureInfo("en-US", false).NumberFormat)); } } } } return(returnTable); }