cesco.zanga@gmail.com

Importing data from a .dat file

Discussion created by cesco.zanga@gmail.com on Sep 23, 2016
Latest reply on Sep 26, 2016 by Susanne.Heip

I'm trying to import data from a .dat file (in this case data.dat). Both the .mos file and the .dat file are in the same directory. However, there is an error in the debug of the program. I have tried to look into the manual but I cannot seem to find any solution. I have also tried to set the PROJECTDIR to the location of the program ('C:\Users\....') but nothing changes. Would any of you be able to tell me where is the mistake and how I can fix it? Please find attached the code and the list of errors.

 


PROGRAM

!@encoding CP1252

model Fourth

uses "mmxprs"; !gain access to the Xpress-Optimizer solver

 

!optional parameters section

parameters

!  SAMPLEPARAM1='c:\test\'

!  SAMPLEPARAM2=false

   PROJECTDIR='' ! for when file is added to project

end-parameters

if PROJECTDIR <> '' then

  setparam('workdir', PROJECTDIR)

  writeln("Project directory: " + PROJECTDIR)

end-if

 

!sample declarations section

declarations

  !Set

  Products: set of string

  Resources: set of string

 

  !Parameters

  x: array(Products) of mpvar

  consumption: array(Products,Resources) of integer

  demand: array(Products) of integer

  stock: array(Resources) of integer

  gain: array(Products) of real

 

  Objective:linctr

end-declarations

 

initializations from “data.dat”

  Products

  Resources

  stock

  gain

  demand

  consumption

end-initializations

 

forall (p in Products) create(x(p))

 

!Constraints

  forall(p in Products) x(p) <= demand(p)

  forall(r in Resources) do

  sum(p in Products) consumption(p,r)*x(p) <= stock(r)

  end-do

  Objective:= sum(p in Products) gain(p)*x(p)

 

  maximize(Objective)

 

writeln("Begin running model")

writeln("End running model")

forall (p in Products) do

writeln("This is the numbre of Spatzle: " + getsol(x(p)))

end-do

 

end-model

ERROR

====versions====

Xpress-IVE Version 1.24.10

Built on Aug  1 2016, 07:07:28

Character encoding: CP1252

Xpress Mosel Version 4.0.2

Xpress Optimizer Version 29.01.10

====messages====

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  32, Col:  22) : error 100: Syntax error before `“'.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  32, Col:  27) : error 123: `data' is not defined.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  32, Col:  31) : error 123: `dat' is not defined.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  33, Col:  10) : warning 124: An expression cannot be used as a statement.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  34, Col:  11) : warning 124: An expression cannot be used as a statement.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  35, Col:   6) : warning 124: An expression cannot be used as a statement.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  36, Col:   5) : warning 124: An expression cannot be used as a statement.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  37, Col:   8) : warning 124: An expression cannot be used as a statement.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  38, Col:  12) : warning 124: An expression cannot be used as a statement.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  39, Col:  19) : error 100: Syntax error before `initializations'.

C:\Users\cesco\Desktop\xpress slides\Exercise\fourth.mos(Line:  39, Col:  19) : error 168: `end-model' expected here.

======end=======

Outcomes