Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:41:29+00:00 2026-06-13T11:41:29+00:00

assuming we have: set U of n-dimensional vectors (vector v = < x1,x2 …

  • 0

assuming we have:

  • set U of n-dimensional vectors (vector v = < x1,x2 … ,xn >)
  • constraint n-dimensional vector c = < x1…xn >
  • n-dimensional vector of weights w = < x1…xn >
  • integer S

i need algorithm that would select S vectors from U into set R while minimizing function cost(R)

cost(R) = sum(abs(c-sumVectors(R))*w)

(sumVectors is a function that sums all vectors like so: sumVectors({< 1,2 >; < 3 ,4>}) = < 4,6 > while sum(< 1, 2, 3 >) returns scalar 6)

The solution does not have to be optimal. I just need to get a best guess i can get in preset time.

Any idea where to start? (Preferably something faster/smarter than genetic algorithms)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:41:30+00:00Added an answer on June 13, 2026 at 11:41 am

    This is an optimization problem. Since you don’t need the optimal solution, you can try the stochastic optimization method, e.g., Hill Climbing, in which you start with a random solution (a random subset of R) and look at the set of neighboring solutions (adding or removing one of the components of current solution) for those that are better with respective of the cost function.

    To get better solution, you can also add Simulated Annealing to your hill climbing search. The idea is that in some cases, it’s necessary to move to a worse solution and then arrive at a better one later. Simulated Annealing works better because it allows a move for a worse solution near the beginning of the process. The algorithm becomes less likely to allow a worse solution as the process goes on.

    I paste some sample hill climbing python code to solve your problem here:
    https://gist.github.com/921f398d61ad351ac3d6

    In my sample code, R always holds a list of the index into U, and I use euclidean distance to compare the similarity between neighbors. Certainly you can use other distance functions that satisfy your own needs. Also note in the code, I am getting neighbors on the fly. If you have a large pool of vectors in U, you might want to cache the pre-computed neighbors or even consider locality sensitive hashing to avoid O(n^2) comparison. Simulated Annealing can be added onto the above code.

    The result of one random run is shown below.

    I use only 20 vectors in U, S=10, so that I can compare the result with an optimal solution.
    The hill climbing process stops at the 4th step when there is no better choice to move to with replacing only one k-nearest-neighbors.

    I also run with an exhaustive search which iterates all possible combinations. You can see that the hill-climbing result is pretty good compared with the exhaustive approach. It takes only 4 steps to get the relatively small cost (a local minimum though) which takes the exhaustive search more than 82K steps to beat it.

    initial R [1, 3, 4, 5, 6, 11, 13, 14, 15, 17]
    hill-climbing cost at step      1: 91784
    hill-climbing cost at step      2: 89574
    hill-climbing cost at step      3: 88664
    hill-climbing cost at step      4: 88503
    exhaustive search cost at step      1: 94165
    exhaustive search cost at step      2: 93888
    exhaustive search cost at step      4: 93656
    exhaustive search cost at step      5: 93274
    exhaustive search cost at step     10: 92318
    exhaustive search cost at step     44: 92089
    exhaustive search cost at step     50: 91707
    exhaustive search cost at step     84: 91561
    exhaustive search cost at step     99: 91329
    exhaustive search cost at step    105: 90947
    exhaustive search cost at step    235: 90718
    exhaustive search cost at step    255: 90357
    exhaustive search cost at step   8657: 90271
    exhaustive search cost at step   8691: 90129
    exhaustive search cost at step   8694: 90048
    exhaustive search cost at step  19637: 90021
    exhaustive search cost at step  19733: 89854
    exhaustive search cost at step  19782: 89622
    exhaustive search cost at step  19802: 89261
    exhaustive search cost at step  20097: 89032
    exhaustive search cost at step  20131: 88890
    exhaustive search cost at step  20134: 88809
    exhaustive search cost at step  32122: 88804
    exhaustive search cost at step  32125: 88723
    exhaustive search cost at step  32156: 88581
    exhaustive search cost at step  69336: 88506
    exhaustive search cost at step  82628: 88420
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming that we have a set of elements and want to store them in
I have a set of templates/functions that allow me to print a tuple/pair assuming
I have set android:targetSdkVersion=15 and build SDK to 15 as well assuming that app
Assuming I have a large set of Coordinates such us (3,4) , (5,-6) ,
Assuming all my Gradle plugin user going to have a MYAPP_HOME sys variable set
Assuming I have a ASP.NET MVC 3 application that runs in a web farm
This is likely a novice question about LINQ, but assuming I have a set
Assuming I have entries in a datastore that reference other datastore entities: id link
assuming I have defined a HashSet<String> set . What is better in terms of
Assuming I have a simple structure that looks like this: public class Range {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.