How to correct Knapsack compiling error MiniZinc? - knapsack-problem

What can I do for correcting errors in the following program
item= record( int: id, profit, weight);
set of item: All_Items ;
int :Max_Capacity;
var set of item: Selected_Items;
I have the following code for solving knapsack in MiniZinc, but it has many errors.
constraint sum([holds(X in Selected_Items)*X.weight | X in All_Items])=< Max_Capacity;
constraint Selected_Items >= All_Items;
maximize
sum([holds(S in Selected_Items)*S.profit |S in All_Items]);
Errors List
Compiling knapsack1.mzn
C:/Program Files/MiniZinc IDE (bundled)/examples/knapsack1.mzn:3.7-12:
item= record( int: id, profit, weight);
^^^^^^
Error: syntax error, unexpected record
C:/Program Files/MiniZinc IDE (bundled)/examples/knapsack1.mzn:11.45:
constraint sum([holds(X in Selected_Items)*X.weight | X in All_Items])=< Max_Capacity;
^
Error: syntax error, unexpected $undefined, expecting ]
C:/Program Files/MiniZinc IDE (bundled)/examples/knapsack1.mzn:15.1-8:
maximize
^^^^^^^^
Error: syntax error, unexpected maximize, expecting end of file
Process finished with non-zero exit code 1
Finished in 89msec

Although MiniZinc currently does not contain any record-types (read struct like types), they are a possibility for the future. To prevent breaking models in the future, the word record is therefore already a reserved keyword and can not be used in as an identifier in your model. Changing the name from record to something else will fix your problem.

Related

gcc / clang: -fmax-errors / -ferror-limit: why the triggering condition is "exceeded" rather than "reached"?

Sample code (t999.c):
int_ x;
Incvocatoins:
$ gcc t999.c -fmax-errors=1
t999.c:1:1: error: unknown type name ‘int_’; did you mean ‘int’?
1 | int_ x;
| ^~~~
| int
$ clang t999.c -ferror-limit=1
t999.c:1:1: error: unknown type name 'int_'; did you mean 'int'?
int_ x;
^~~~
int
1 error generated.
Here we see that:
gcc have not generated compilation terminated due to -fmax-errors=1.
clang have not generated fatal error: too many errors emitted, stopping now [-ferror-limit=].
Conclusion: in both gcc and clang the triggering condition is "exceeded" rather than "reached".
Descriptions:
-fmax-errors=n
Limits the maximum number of error messages to n, at which point GCC
bails out rather than attempting to continue processing the source
code.
-ferror-limit=123
Stop emitting diagnostics after 123 errors have been produced.
Questions:
Why the triggering condition is "exceeded" rather than "reached"?
Should the triggering condition be "reached" rather than "exceeded"?
(extra) Does the current behavior ("exceeded" rather than "reached") correspond to the descriptions above?

I met a error warning when run regression model for a panel using plm package

I have a panel for 27 years, but met this warning when I run a regression.
panel data of global suicide rate with temperature
I use the following codes:
library(plm)
install.packages("dummies")
library(dummies)
data2 <- cbind(mydata, dummy(mydata$year, sep ="_"))
suicide_fe <- plm(suiciderate ~ dmt, data2, index = c("country", "year"),
model= "within")
summary(suicide_fe)
But I got this error:
Error in pdim.default(index[[1]], index[[2]]) :
duplicate couples (id-time)
In addition: Warning messages:
1: In pdata.frame(data, index) :
duplicate couples (id-time) in resulting pdata.frame to find out which, use
e.g. table(index(your_pdataframe), useNA = "ifany") 2: In
is.pbalanced.default(index[[1]], index[[2]]) :
duplicate couples (id-time)

Fortran error #5082: Syntax error, found IDENTIFIER when expecting one of: <END-OF-STATEMENT> ;

I am "making" a code.
The compilation with make fails producing this error
mpif90 -mkl -O3 -no-prec-div -fpp -openmp -xHost -DMPI -DEFTCOSMOMC -module ReleaseEFTMPI -IReleaseEFTMPI/ -c equations_EFT.f90 -o ReleaseEFTMPI/equations_EFT.o
equations_EFT.f90(267): error #5082: Syntax error, found IDENTIFIER 'EFTCAMBINITIALCONDITIONS' when expecting one of: <END-OF-STATEMENT> ;
module subroutine EFTCAMBInitialConditions( y, EV, tau )
--------------------------^
equations_EFT.f90(267): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % [ . = =>
module subroutine EFTCAMBInitialConditions( y, EV, tau )
----------------------------------------------------------------^
equations_EFT.f90(271): error #6786: This is an invalid statement; an END [MODULE] statement is required.
end subroutine EFTCAMBInitialConditions
--------^
equations_EFT.f90(271): error #6758: This name is invalid; if a name is present, it must match the corresponding interface body name. [EFTCAMBINITIALCONDITIONS]
end subroutine EFTCAMBInitialConditions
-----------------------^
equations_EFT.f90(268): error #6457: This derived type name has not been declared. [EVOLUTIONVARS]
type(EvolutionVars) EV
-----------------^
equations_EFT.f90(269): error #6683: A kind type parameter must be a compile-time constant. [DL]
real(dl) :: y(EV%nvar)
-----------------^
equations_EFT.f90(269): error #6535: This variable or component must be of a derived or structure type [EV]
real(dl) :: y(EV%nvar)
--------------------------^
equations_EFT.f90(269): error #6460: This is not a field name that is defined in the encompassing structure. [NVAR]
real(dl) :: y(EV%nvar)
-----------------------------^
equations_EFT.f90(269): error #6223: A specification expression is invalid. [NVAR]
real(dl) :: y(EV%nvar)
-----------------------------^
equations_EFT.f90(270): error #6683: A kind type parameter must be a compile-time constant. [DL]
real(dl) :: tau
-----------------^
equations_EFT.f90(269): error #6279: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association [EV]
real(dl) :: y(EV%nvar)
--------------------------^
compilation aborted for equations_EFT.f90 (code 1)
I attach the snippet from equations_EFT.f90
interface
module subroutine EFTCAMBInitialConditions( y, EV, tau )
type(EvolutionVars) EV
real(dl) :: y(EV%nvar)
real(dl) :: tau
end subroutine EFTCAMBInitialConditions
end interface
Is there something wrong in this snippet? It is strange because this is distributed software, but I have literally just followed the instruction to make the code.
The code of the question is an example of using submodules, a feature newly introduced into Fortran in the 2008 revision. To compile this code you will need a compiler which understands this concept.
The GNU and Intel compilers are examples of such, but you will need an appropriate version.

C++: C2511: Overloaded member function not found. problems when using 'this'

I have this one object that tries to call a function in another class's function. That function looks like this (Belongs to class 'Player' ):
void play(Game *const currentGame, int x, int y);
When I try to call this function from another object (of the Game class) like this :
player->play(this, x, y)
And during compilation I get these errors:
Error 1 error C2061: syntax error : identifier 'Game' c:\users\shaqed\documents\visual studio 2013\projects\exe3\tictactoe.h 24 1 Exe3
Error 3 error C2511: 'void Player::play(Game *const ,int,int)' : overloaded member function not found in 'Player' c:\users\shaqed\documents\visual studio 2013\projects\exe3\tictactoe.cpp 40 1 Exe3
Error 4 error C2660: 'Player::play' : function does not take 3 arguments c:\users\shaqed\documents\visual studio 2013\projects\exe3\tictactoe.cpp 158 1 Exe3
I came from Java, so maybe I lack some of the core principles about pointers and reference, however I could figure out why there's a type mismatch in here.
Thanks in advance
I have repeated your problem with the same compile errors. I think you have forgotten to add at the end of your method the body. Like:
void play(const Game *currentGame, int x, int y){}

How to solve distinct-values error

How to solve this error in XQuery. I want the data to be distinct with out duplication in XML result. I tried to add distinct-values in front of the doc in for statement, but this error was depicted.
Engine name: Saxon-PE XQuery 9.5.1.3
Severity: fatal
Description: XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtomicType
Start location: 23:0
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0019
This is code :
for $sv1 in distinct-values(doc('tc.xml')//term/year)
let $sv2 := doc('tc.xml')//term[year= $sv1]
let $sv3 := doc('tc.xml')//student[idStudent= $sv1/idStudent](:HERE IS THE ERROR LINE:)
let $sv4 := doc('tc.xml')//program[idStudent= $sv3/idStudent]
return
<Statistics>
{$sv1 }
<Count_Student>{count($sv2)}</Count_Student>
<a50_60>{count(doc('tc.xml')/mydb//program[doc('tc.xml')/mydb//term/year =$sv1][avg>= 50 and avg < 60])}</a50_60>
</Statistics>
thank you in advance.
distinct-values() will atomize your input, this means that $sv1/idStudent won't work because $sv1 is not an element. Instead of using $sv1 on the line that give an error I think you should be using $sv2.

Resources