<commit_before>package org.muml.psm.allocation.algorithm.ilp.opt4j.evaluation

import java.util.Map
import org.muml.core.expressions.Expression
import org.muml.core.expressions.common.ArithmeticExpression
import org.muml.core.expressions.common.ArithmeticOperator
import org.muml.core.expressions.common.LiteralExpression
import org.muml.psm.allocation.ilp.Variable
import org.muml.psm.allocation.ilp.VariableExpression

class ObjectiveFunctionExpressionEvaluator {
	
	static class Environment {
		val Map<String, Boolean> allocation
		
		new(Map<String, Boolean> allocation) {
			this.allocation = allocation
		}
		
		def double lookup(Variable variable) {
			val Boolean value = allocation.get(variable.name)
			if (value == null) {
				throw new IllegalArgumentException("env has no variable: " + variable.name.ToString)
			}
			if (value) 1 else 0
		}
	}
	
	val Environment environment
	
	new(Map<String, Boolean> allocation) {
		environment = new Environment(allocation)
	}
	
	def static double evaluate(Expression expression, Map<String, Boolean> allocation) {
		new ObjectiveFunctionExpressionEvaluator(allocation).evaluate(
			expression
		)
	}
	
	public def dispatch double evaluate(Expression expression) {
		throw new IllegalArgumentException("unsupported expression: " + expression)
	}
	
	public def dispatch double evaluate(ArithmeticExpression expression) {
		val left = evaluate(expression.leftExpression)
		val right = evaluate(expression.rightExpression)<commit_msg>[PSM] adjusted imports of the psm.transformation's qvto transformations<commit_after>package org.muml.psm.allocation.algorithm.ilp.opt4j.evaluation

import java.util.Map
import org.muml.core.expressions.Expression
import org.muml.core.expressions.common.ArithmeticExpression
import org.muml.core.expressions.common.ArithmeticOperator
import org.muml.core.expressions.common.LiteralExpression
import org.muml.psm.allocation.ilp.Variable
import org.muml.psm.allocation.ilp.VariableExpression

class ObjectiveFunctionExpressionEvaluator {
	
	static class Environment {
		val Map<String, Boolean> allocation
		
		new(Map<String, Boolean> allocation) {
			this.allocation = allocation
		}
		
		def double lookup(Variable variable) {
			val Boolean value = allocation.get(variable.name)
			if (value == null) {
				throw new IllegalArgumentException("env has no variable: ".concat(variable.name))
			}
			if (value) 1 else 0
		}
	}
	
	val Environment environment
	
	new(Map<String, Boolean> allocation) {
		environment = new Environment(allocation)
	}
	
	def static double evaluate(Expression expression, Map<String, Boolean> allocation) {
		new ObjectiveFunctionExpressionEvaluator(allocation).evaluate(
			expression
		)
	}
	
	public def dispatch double evaluate(Expression expression) {
		throw new IllegalArgumentException("unsupported expression: " + expression)
	}
	
	public def dispatch double evaluate(ArithmeticExpression expression) {
		val left = evaluate(expression.leftExpression)
		val right = evaluate(expression.rightExpression)
{'fraction_non_alphanumeric': 0.08440913604766634, 'fraction_numerical': 0.0019860973187686196, 'mean_word_length': 5.154786150712831, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '24464', 'n_tokens_mistral': 937, 'n_tokens_neox': 828, 'n_words': 198}